Skip to content

Attributes containing rustc#153532

Open
jdonszelmann wants to merge 2 commits intorust-lang:mainfrom
jdonszelmann:attributes-containing-rustc
Open

Attributes containing rustc#153532
jdonszelmann wants to merge 2 commits intorust-lang:mainfrom
jdonszelmann:attributes-containing-rustc

Conversation

@jdonszelmann
Copy link
Contributor

r? @petrochenkov

I noticed that attributes containing the word rustc as a segment also error with a message referring to "starting with rustc". The first commit shows this going wrong by re-exporting #[test], a built-in macro, from a module called rustc.

The 2nd commit addresses this by changing the diagnostic. However, given the wording I wonder if the real solution shouldn't be to allow attributes containing a rustc segment and only disallow them when they start. In other words, actually implement the behavior that the original diagnostic pointed out.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 7, 2026
@jdonszelmann
Copy link
Contributor Author

@jdonszelmann jdonszelmann force-pushed the attributes-containing-rustc branch from f7db4d8 to 53123a4 Compare March 7, 2026 09:40
@jdonszelmann jdonszelmann force-pushed the attributes-containing-rustc branch from 53123a4 to f6b4e4e Compare March 7, 2026 09:41
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the attributes-containing-rustc branch from f6b4e4e to 951e9d7 Compare March 9, 2026 09:19
@jdonszelmann
Copy link
Contributor Author

Removed the test I added in commit 1, since we already test similar behavior somewhere else (see the other test I blessed). Kept it in the first commit to demonstrate old behavior.

Copy link
Contributor

@JonathanBrouwer JonathanBrouwer left a comment

Choose a reason for hiding this comment

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

Not sure if you want specifically petrochenkov to take a look, if not r=me

View changes since this review

@@ -618,15 +612,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

// Report errors for the resolved macro.
let mut first = true;
for segment in &path.segments {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd prefer doing this with enumerate rather than a variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants