From 814e36f7c632ca4fb1d003fe67b059aaac079178 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sat, 30 May 2026 12:10:40 +0200 Subject: [PATCH 1/2] Revert "drop derive helpers during ast lowering" This reverts commit 29e92731 --- compiler/rustc_attr_parsing/src/interface.rs | 23 +++----------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index eb49f108b0414..ffe0451f29aa9 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -285,11 +285,6 @@ impl<'sess> AttributeParser<'sess> { mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute), ) -> Vec { let mut attributes = Vec::new(); - // We store the attributes we intend to discard at the end of this function in order to - // check they are applied to the right target and error out if necessary. In practice, we - // end up dropping only derive attributes and derive helpers, both being fully processed - // at macro expansion. - let mut dropped_attributes = Vec::new(); let mut attr_paths: Vec> = Vec::new(); let mut early_parsed_state = EarlyParsedState::default(); @@ -437,20 +432,8 @@ impl<'sess> AttributeParser<'sess> { self.check_invalid_crate_level_attr_item(&attr, n.item.span()); } - let attr = Attribute::Unparsed(Box::new(attr)); - - if self.tools.is_some_and(|tools| { - tools.iter().any(|tool| tool.name == parts[0]) - // FIXME: this can be removed once #152369 has been merged. - // https://github.com/rust-lang/rust/pull/152369 - || [sym::allow, sym::deny, sym::expect, sym::forbid, sym::warn] - .contains(&parts[0]) - }) { - attributes.push(attr); - } else { - dropped_attributes.push(attr); - } - } + attributes.push(Attribute::Unparsed(Box::new(attr))); + }; } } } @@ -466,7 +449,7 @@ impl<'sess> AttributeParser<'sess> { } if !matches!(self.should_emit, ShouldEmit::Nothing) && target == Target::WherePredicate { - self.check_invalid_where_predicate_attrs(attributes.iter().chain(&dropped_attributes)); + self.check_invalid_where_predicate_attrs(attributes.iter()); } attributes From 5be84518f437d9872cb42322d32a80b39e17a6ec Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sat, 30 May 2026 12:18:29 +0200 Subject: [PATCH 2/2] Add regression test --- tests/rustdoc-json/attrs/derive_helper.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/rustdoc-json/attrs/derive_helper.rs diff --git a/tests/rustdoc-json/attrs/derive_helper.rs b/tests/rustdoc-json/attrs/derive_helper.rs new file mode 100644 index 0000000000000..278d0072decdd --- /dev/null +++ b/tests/rustdoc-json/attrs/derive_helper.rs @@ -0,0 +1,7 @@ +//@ is "$.index[?(@.name=='A')].attrs" '[{"other": "#[default]"}]' +#[derive(Default)] +pub enum Test { + #[default] + A, + B, +}