From b14d12ada9ac840bcbbe515dca30aa74fb6d1a7e Mon Sep 17 00:00:00 2001 From: Bernardo Uriarte Date: Fri, 26 Aug 2022 18:51:51 +0200 Subject: [PATCH] avoid warnings in generated code --- .../salsa-2022-macros/src/salsa_struct.rs | 5 +++-- salsa-2022-tests/tests/warnings/main.rs | 6 ++++++ .../tests/warnings/needless_borrow.rs | 19 +++++++++++++++++++ .../tests/warnings/unused_variable_db.rs | 7 +++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 salsa-2022-tests/tests/warnings/main.rs create mode 100644 salsa-2022-tests/tests/warnings/needless_borrow.rs create mode 100644 salsa-2022-tests/tests/warnings/unused_variable_db.rs diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index ec16042..4374f2f 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -310,14 +310,15 @@ impl SalsaStruct { impl Fallback for Everything {} - &Test::<#field_ty, #db_type>::salsa_debug(&self.#field_getter(db), db) + #[allow(clippy::needless_borrow)] + &Test::<#field_ty, #db_type>::salsa_debug(&self.#field_getter(_db), _db) }) } }).collect::>(); parse_quote_spanned! {ident.span()=> impl ::salsa::DebugWithDb<#db_type> for #ident { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>, db: &#db_type) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>, _db: &#db_type) -> ::std::fmt::Result { f.debug_struct(#ident_string) .field("[salsa id]", &self.0.as_u32()) #(#fields)* diff --git a/salsa-2022-tests/tests/warnings/main.rs b/salsa-2022-tests/tests/warnings/main.rs new file mode 100644 index 0000000..2a8dd82 --- /dev/null +++ b/salsa-2022-tests/tests/warnings/main.rs @@ -0,0 +1,6 @@ +//! Test that macros don't generate code with warnings + +#![deny(warnings)] + +mod needless_borrow; +mod unused_variable_db; diff --git a/salsa-2022-tests/tests/warnings/needless_borrow.rs b/salsa-2022-tests/tests/warnings/needless_borrow.rs new file mode 100644 index 0000000..502d23e --- /dev/null +++ b/salsa-2022-tests/tests/warnings/needless_borrow.rs @@ -0,0 +1,19 @@ +trait Db: salsa::DbWithJar {} + +#[salsa::jar(db = Db)] +struct Jar(TokenTree); + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +enum Token {} + +impl salsa::DebugWithDb for Token { + fn fmt(&self, _f: &mut std::fmt::Formatter<'_>, _db: &dyn Db) -> std::fmt::Result { + unreachable!() + } +} + +#[salsa::tracked(jar = Jar)] +struct TokenTree { + #[return_ref] + tokens: Vec, +} diff --git a/salsa-2022-tests/tests/warnings/unused_variable_db.rs b/salsa-2022-tests/tests/warnings/unused_variable_db.rs new file mode 100644 index 0000000..3298481 --- /dev/null +++ b/salsa-2022-tests/tests/warnings/unused_variable_db.rs @@ -0,0 +1,7 @@ +trait Db: salsa::DbWithJar {} + +#[salsa::jar(db = Db)] +struct Jar(Keywords); + +#[salsa::interned(jar = Jar)] +struct Keywords {}