Skip to content

Commit 31149b5

Browse files
committed
Pass unknown attributes from fields to getter functions in inputs
1 parent 1ad7b4b commit 31149b5

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

components/salsa-macro-rules/src/setup_input_struct.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ macro_rules! setup_input_struct {
3232
// Indices for each field from 0..N -- must be unsuffixed (e.g., `0`, `1`).
3333
field_indices: [$($field_index:tt),*],
3434

35+
// Attributes for each field
36+
field_attrs: [$([$(#[$field_attr:meta]),*]),*],
37+
3538
// Fields that are required (have no default value). Each item is the fields name and type.
3639
required_fields: [$($required_field_id:ident $required_field_ty:ty),*],
3740

@@ -176,6 +179,7 @@ macro_rules! setup_input_struct {
176179
}
177180

178181
$(
182+
$(#[$field_attr])*
179183
$field_getter_vis fn $field_getter_id<'db, $Db>(self, db: &'db $Db) -> $zalsa::return_mode_ty!($field_option, 'db, $field_ty)
180184
where
181185
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`

components/salsa-macros/src/input.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl Macro {
101101
let field_options = salsa_struct.field_options();
102102
let field_tys = salsa_struct.field_tys();
103103
let field_durability_ids = salsa_struct.field_durability_ids();
104+
let field_attrs = salsa_struct.field_attrs();
104105
let is_singleton = self.args.singleton.is_some();
105106
let generate_debug_impl = salsa_struct.generate_debug_impl();
106107

@@ -125,6 +126,7 @@ impl Macro {
125126
field_setters: [#(#field_vis #field_setter_ids),*],
126127
field_tys: [#(#field_tys),*],
127128
field_indices: [#(#field_indices),*],
129+
field_attrs: [#([#(#field_attrs),*]),*],
128130
required_fields: [#(#required_fields),*],
129131
field_durability_ids: [#(#field_durability_ids),*],
130132
num_fields: #num_fields,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[salsa::input]
2+
struct InputWithUnknownAttrs {
3+
/// Doc comment
4+
field: u32,
5+
#[anything]
6+
field2: u32,
7+
}
8+
9+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: cannot find attribute `anything` in this scope
2+
--> tests/compile-fail/input_struct_unknown_attributes.rs:5:7
3+
|
4+
5 | #[anything]
5+
| ^^^^^^^^

0 commit comments

Comments
 (0)