Uh oh!
There was an error while loading. Please reload this page.
Replace check_attr_crate_level with check_target for #[doc] - #161521
Replace check_attr_crate_level with check_target for #[doc]#161521evavh wants to merge 4 commits into
Conversation
rustbot
commented
Aug 22, 2026
Some changes occurred in compiler/rustc_attr_parsing |
| return; | ||
| } | ||
| cx.check_target( | ||
| &sym::no_crate_inject.to_string(), |
There was a problem hiding this comment.
| &sym::no_crate_inject.to_string(), | |
| sym::no_crate_inject.as_str() |
| return; | ||
| } | ||
| cx.check_target( | ||
| &s.to_string(), |
There was a problem hiding this comment.
| &s.to_string(), | |
| s.as_str(), |
This comment has been minimized.
This comment has been minimized.
| return; | ||
| } | ||
| cx.check_target( | ||
| concat!("(", stringify!($ident), ")"), |
There was a problem hiding this comment.
Could you make tests for these cases if they don't already exist? I'd expect some stderr changes in this PR
rustbot
commented
Aug 22, 2026
Reminder, once the PR becomes ready for a review, use |
evavh
commented
Aug 28, 2026
I tried to add tests for the crate-level attribute checks, but I'm running into an interesting problem: there seems to be no way for the target check to fail. The possible ways for a crate-level attribute to be applied to a non-crate target (that I can think of) are:
In both cases the compiler throws an error before we even reach the target checking code in doc.rs. The same applies to doc attribute arguments that shouldn't be used crate-level, like The test I wrote covers all doc attribute arguments that check whether they are applied at crate level, and they all throw errors in earlier parsing steps. What do we do with the target checking code that does nothing? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@evavh I took a random crate-level doc attribute, and applied it to a function: #[doc(html_no_source)]fntest1(){}fntest2(){#![doc(html_no_source)]}In both cases this produces "this attribute can only be applied at the crate level" The diagnostic "an inner attribute is not permitted in this context" is produced when you apply inner attributes to an item that doesn't support inner attributes, such as a struct, and is indeed produced in the parser structTest{#![doc(html_no_source)]}@rustbot author |
6c2968e to
7a056e3Comparerustbot
commented
Aug 31, 2026
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
These are breaking changes, so they will need a crater run. Alternatively, you could refactor this in a way that doesn't change behavior. |
Turns out I was very confused by the "new" diagnostic emitted by I tried changing the diagnostic in As for breaking changes, using a crate-level @rustbot ready |
| } | ||
| cx.check_target( | ||
| sym::no_crate_inject.as_str(), | ||
| &AllowedTargets::AllowList(&[Allow(Target::Crate)]), |
There was a problem hiding this comment.
If you use AllowListWarnRest instead of AllowList it will warn instead of erroring.
Then to generate the right lint INVALID_DOC_ATTRIBUTES instead of the default UNUSED_ATTRIBUTES we should add a special case here
| //! This is not an official rust crate | ||
| #[doc(rust_logo)] | ||
| //~^ WARN this attribute can only be applied at the crate level |
There was a problem hiding this comment.
Is there a reason you removed this from the test?
This is here to show that this doc attribute, incorrectly, is not feature gated
rust-log-analyzer
commented
Sep 1, 2026
The job Click to see the possible cause of the failure (guessed by this bot) |
A small change as part of the target checking refactor for #[doc] attribute parsing.
r? @JonathanBrouwer