Skip to content

Commit

Permalink
Emit compiler errors for unknown field attributes
Browse files Browse the repository at this point in the history
Emit an error if an unknown field attribute is used on a
`salsa::tracked` struct. For example, when changing the `return_ref`
attribute in `ParsedFile` to `returns_ref`, the compiler emits:

    error: unrecognized field attribute
       --> examples/lazy-input/main.rs:164:5
        |
    164 |     #[returns_ref]
        |     ^^^^^^^^^^^^^^
  • Loading branch information
sharkdp committed Feb 25, 2025
1 parent 0177525 commit 1b1bd2d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/salsa-macros/src/salsa_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,20 @@ impl<'s> SalsaField<'s> {

// Scan the attributes and look for the salsa attributes:
for attr in &field.attrs {
let mut found = false;
for (fa, func) in FIELD_OPTION_ATTRIBUTES {
if attr.path().is_ident(fa) {
func(attr, &mut result);
found = true;
}
}

if !found {
return Err(syn::Error::new_spanned(
attr,
"unrecognized field attribute",
));
}
}

Ok(result)
Expand Down

0 comments on commit 1b1bd2d

Please sign in to comment.