From 7c8647e572bc52e040a26a7b321b61efa2ce307c Mon Sep 17 00:00:00 2001 From: DropDemBits Date: Wed, 15 Mar 2023 09:56:00 -0400 Subject: [PATCH] Allow clippy::needless_lifetimes on tracked method getters Previously, this would necessitate having to manually add an allow for this clippy lint, since an extra `'db` lifetime was added to the signature. --- .../salsa-2022-macros/src/tracked_fn.rs | 6 +++++ salsa-2022-tests/tests/warnings/main.rs | 1 + .../tests/warnings/needless_lifetimes.rs | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 salsa-2022-tests/tests/warnings/needless_lifetimes.rs diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index f4bbcc36..b458332e 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -234,6 +234,12 @@ fn tracked_method( let (config_ty, fn_struct) = crate::tracked_fn::fn_struct(&args, &item_fn)?; + // we generate a `'db` lifetime that clippy + // sometimes doesn't like + item_method + .attrs + .push(syn::parse_quote! {#[allow(clippy::needless_lifetimes)]}); + item_method.block = getter_fn( &args, &mut item_method.sig, diff --git a/salsa-2022-tests/tests/warnings/main.rs b/salsa-2022-tests/tests/warnings/main.rs index 2a8dd82f..77438e53 100644 --- a/salsa-2022-tests/tests/warnings/main.rs +++ b/salsa-2022-tests/tests/warnings/main.rs @@ -3,4 +3,5 @@ #![deny(warnings)] mod needless_borrow; +mod needless_lifetimes; mod unused_variable_db; diff --git a/salsa-2022-tests/tests/warnings/needless_lifetimes.rs b/salsa-2022-tests/tests/warnings/needless_lifetimes.rs new file mode 100644 index 00000000..19b322cf --- /dev/null +++ b/salsa-2022-tests/tests/warnings/needless_lifetimes.rs @@ -0,0 +1,27 @@ +pub trait Db: salsa::DbWithJar {} + +#[salsa::jar(db = Db)] +pub struct Jar(SourceTree, SourceTree_all_items, use_tree); + +#[derive(Debug, PartialEq, Eq, Hash)] +pub struct Item {} + +#[salsa::tracked(jar = Jar)] +pub struct SourceTree {} + +#[salsa::tracked(jar = Jar)] +impl SourceTree { + #[salsa::tracked(return_ref)] + pub fn all_items(self, _db: &dyn Db) -> Vec { + todo!() + } +} + +#[salsa::tracked(jar = Jar, return_ref)] +fn use_tree(_db: &dyn Db, _tree: SourceTree) {} + +#[allow(unused)] +fn use_it(db: &dyn Db, tree: SourceTree) { + tree.all_items(db); + use_tree(db, tree); +}