fix(ast): prevent greyed out fields in AST types in IDEs (#28335)

At some point Rust Analyzer started greying out the fields of AST structs in VS Code due to a strange interaction with the `#[ast]` macro. Fix this by making the macro add an `#[allow(rust_analyzer::inactive_code)]` attribute to struct fields.
This commit is contained in:
overlookmotel committed 2026-10-28 22:43:14 +00:00
1 parent 01553fdf9d
commit 052bca9c98
1 file changed
+4
+4
View File
@@ -274,8 +274,12 @@ fn reorder_struct_fields(
let mut fields = named.clone().into_pairs().zip(field_order).collect::<Vec<_>>();
fields.sort_unstable_by_key(|(_, index)| **index);
// `#[allow(rust_analyzer::inactive_code)]` stops rust-analyzer greying out the fields in source.
// The `#[cfg(doc)]` copies have the same spans as the source fields, so rust-analyzer maps
// the "inactive code" diagnostic for them back onto the source.
for field in named.iter_mut() {
field.attrs.insert(0, parse_quote!( #[cfg(doc)]));
field.attrs.insert(1, parse_quote!( #[allow(rust_analyzer::inactive_code)]));
}
named.extend(fields.into_iter().map(|(mut pair, _)| {