diff --git a/components/salsa-macro-rules/src/setup_input_struct.rs b/components/salsa-macro-rules/src/setup_input_struct.rs index 02ee01c09..ab5c15bfa 100644 --- a/components/salsa-macro-rules/src/setup_input_struct.rs +++ b/components/salsa-macro-rules/src/setup_input_struct.rs @@ -110,7 +110,7 @@ macro_rules! setup_input_struct { pub fn ingredient_mut(db: &mut dyn $zalsa::Database) -> (&mut $zalsa_struct::IngredientImpl, &mut $zalsa::Runtime) { let zalsa_mut = db.zalsa_mut(); - let current_revision = zalsa_mut.new_revision(); + zalsa_mut.new_revision(); let index = zalsa_mut.add_or_lookup_jar_by_type::<$zalsa_struct::JarImpl<$Configuration>>(); let (ingredient, runtime) = zalsa_mut.lookup_ingredient_mut(index); let ingredient = ingredient.assert_type_mut::<$zalsa_struct::IngredientImpl>(); diff --git a/components/salsa-macros/src/tracked_impl.rs b/components/salsa-macros/src/tracked_impl.rs index faa387da1..256eae3f5 100644 --- a/components/salsa-macros/src/tracked_impl.rs +++ b/components/salsa-macros/src/tracked_impl.rs @@ -298,7 +298,22 @@ impl Macro { ) -> syn::Result<()> { if let Some(returns) = &args.returns { if let syn::ReturnType::Type(_, t) = &mut sig.output { - **t = parse_quote!(& #db_lt #t) + if returns == "copy" || returns == "clone" { + // leave as is + } else if returns == "ref" { + **t = parse_quote!(& #db_lt #t) + } else if returns == "deref" { + **t = parse_quote!(& #db_lt <#t as ::core::ops::Deref>::Target) + } else if returns == "as_ref" { + **t = parse_quote!(<#t as ::salsa::SalsaAsRef>::AsRef<#db_lt>) + } else if returns == "as_deref" { + **t = parse_quote!(<#t as ::salsa::SalsaAsDeref>::AsDeref<#db_lt>) + } else { + return Err(syn::Error::new_spanned( + returns, + format!("Unknown returns mode `{returns}`"), + )); + } } else { return Err(syn::Error::new_spanned( returns, diff --git a/tests/tracked_method_inherent_return_deref.rs b/tests/tracked_method_inherent_return_deref.rs new file mode 100644 index 000000000..2477b5a1d --- /dev/null +++ b/tests/tracked_method_inherent_return_deref.rs @@ -0,0 +1,31 @@ +use salsa::Database; + +#[salsa::input] +struct Input { + number: usize, +} + +#[salsa::tracked] +impl Input { + #[salsa::tracked(returns(deref))] + fn test(self, db: &dyn salsa::Database) -> Vec { + (0..self.number(db)).map(|i| format!("test {i}")).collect() + } +} + +#[test] +fn invoke() { + salsa::DatabaseImpl::new().attach(|db| { + let input = Input::new(db, 3); + let x: &[String] = input.test(db); + + assert_eq!( + x, + &[ + "test 0".to_string(), + "test 1".to_string(), + "test 2".to_string() + ] + ); + }) +}