Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ impl<'sess> AttributeParser<'sess> {
mut emit_lint: impl FnMut(LintId, MultiSpan, EmitAttribute),
) -> Vec<Attribute> {
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<RefPathParser<'_>> = Vec::new();
let mut early_parsed_state = EarlyParsedState::default();

Expand Down Expand Up @@ -452,7 +457,19 @@ impl<'sess> AttributeParser<'sess> {
self.check_invalid_crate_level_attr_item(&attr, inner_span);
}

attributes.push(Attribute::Unparsed(Box::new(attr)));
let attr = Attribute::Unparsed(Box::new(attr));

if self.sess.opts.actually_rustdoc
|| self.tools.is_some_and(|t| t.iter().any(|i| i.name == parts[0]))
// FIXME: this can be removed once #152369 has been merged.

@Kivooeo Kivooeo Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it me or #152369 is merged?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was reverted I think

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, can you link the actual pr to make it less confusing then

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the revert #155056
this has not been merged yet #155691

// 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);
}
};
}
}
Expand All @@ -476,7 +493,7 @@ impl<'sess> AttributeParser<'sess> {
}

if !matches!(self.should_emit, ShouldEmit::Nothing) && target == Target::WherePredicate {
self.check_invalid_where_predicate_attrs(attributes.iter());
self.check_invalid_where_predicate_attrs(attributes.iter().chain(&dropped_attributes));
}

attributes
Expand Down
Loading