mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
Use #[salsa::tracked] for tracked methods
This changes tracked methods from being annotated with `#[tracked]` to `#[salsa::tracked]`. This improves consistency and allows outputting a nicer error message if someone forgets to put the attribute on the impl block.
This commit is contained in:
parent
dbc4154419
commit
2df88d2c33
2 changed files with 17 additions and 8 deletions
|
@ -18,6 +18,13 @@ pub(crate) fn tracked_fn(
|
|||
));
|
||||
}
|
||||
|
||||
if let syn::FnArg::Receiver(receiver) = &item_fn.sig.inputs[0] {
|
||||
return Err(syn::Error::new(
|
||||
receiver.span(),
|
||||
"#[salsa::tracked] must also be applied to the impl block for tracked methods",
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(s) = &args.specify {
|
||||
if requires_interning(&item_fn) {
|
||||
return Err(syn::Error::new(
|
||||
|
@ -96,10 +103,12 @@ pub(crate) fn tracked_impl(
|
|||
_ => return None,
|
||||
};
|
||||
let salsa_tracked_attr = item_method.attrs.iter().position(|attr| {
|
||||
attr.path
|
||||
.get_ident()
|
||||
.map(|ident| ident == "tracked")
|
||||
.unwrap_or(false)
|
||||
let path = &attr.path.segments;
|
||||
path.len() == 2
|
||||
&& path[0].arguments == syn::PathArguments::None
|
||||
&& path[0].ident == "salsa"
|
||||
&& path[1].arguments == syn::PathArguments::None
|
||||
&& path[1].ident == "tracked"
|
||||
})?;
|
||||
let salsa_tracked_attr = item_method.attrs.remove(salsa_tracked_attr);
|
||||
let inner_args = if !salsa_tracked_attr.tokens.is_empty() {
|
||||
|
|
|
@ -7,19 +7,19 @@ struct Jar(MyInput, MyInput_tracked_fn, MyInput_tracked_fn_ref);
|
|||
|
||||
trait Db: salsa::DbWithJar<Jar> {}
|
||||
|
||||
#[salsa::input(jar = Jar)]
|
||||
#[salsa::input]
|
||||
struct MyInput {
|
||||
field: u32,
|
||||
}
|
||||
|
||||
#[salsa::tracked(jar = Jar)]
|
||||
#[salsa::tracked]
|
||||
impl MyInput {
|
||||
#[tracked]
|
||||
#[salsa::tracked]
|
||||
fn tracked_fn(self, db: &dyn Db) -> u32 {
|
||||
self.field(db) * 2
|
||||
}
|
||||
|
||||
#[tracked(return_ref)]
|
||||
#[salsa::tracked(return_ref)]
|
||||
fn tracked_fn_ref(self, db: &dyn Db) -> u32 {
|
||||
self.field(db) * 3
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue