Repository navigation
Replace check_attr_crate_level with check_target for #[doc] - #161521
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
|
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)]
fn test1() { }
fn test2() {
#![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 struct Test {
#![doc(html_no_source)]
}@rustbot author |
6c2968e to
7a056e3
Compare
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
8433ebe to
873c9c0
Compare
|
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. |
|
@bors r+ rollup |
|
📋 This PR cannot be approved because it currently has the following labels: |
|
@bors r+ rollup |
…athanBrouwer Replace check_attr_crate_level with check_target for #[doc] A small change as part of the target checking refactor for #[doc] attribute parsing. r? @JonathanBrouwer
…athanBrouwer Replace check_attr_crate_level with check_target for #[doc] A small change as part of the target checking refactor for #[doc] attribute parsing. r? @JonathanBrouwer
…uwer Rollup of 12 pull requests Successful merges: - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs) - #163219 (assumptions_on_binders: Test mixed ambiguous ORs) - #164985 (Only recover if we may for `recover_missing_dot`) - #161521 (Replace check_attr_crate_level with check_target for #[doc]) - #162530 (Move #[naked] attribute check to attribute parsing stage) - #164103 (trait solver: Resolve region vars before eager placeholder handling) - #164692 (move `ppcf128` lang item to `core::num::imp`) - #164702 (Point at `impl` through which associated function is provided) - #164776 (Account for trait object with implicit `'static` lifetime in field type being returned) - #164791 (Self param after const param) - #164856 (Switch from `insta` to `expect-test` in bootstrap) - #164888 (Add regression tests for #156380)
…uwer Rollup of 14 pull requests Successful merges: - #163219 (assumptions_on_binders: Test mixed ambiguous ORs) - #164985 (Only recover if we may for `recover_missing_dot`) - #161521 (Replace check_attr_crate_level with check_target for #[doc]) - #162530 (Move #[naked] attribute check to attribute parsing stage) - #164103 (trait solver: Resolve region vars before eager placeholder handling) - #164692 (move `ppcf128` lang item to `core::num::imp`) - #164702 (Point at `impl` through which associated function is provided) - #164741 (Use explicit target cpu in tests parsing generated asm) - #164767 (Add regression tests for transmutability issues) - #164776 (Account for trait object with implicit `'static` lifetime in field type being returned) - #164791 (Self param after const param) - #164856 (Switch from `insta` to `expect-test` in bootstrap) - #164888 (Add regression tests for #156380) - #164967 (Add codegen test for power of two implying nonzero with debuginfo)
Rollup merge of #161521 - evavh:doc-crate-level-check, r=JonathanBrouwer Replace check_attr_crate_level with check_target for #[doc] A small change as part of the target checking refactor for #[doc] attribute parsing. r? @JonathanBrouwer
…uwer Rollup of 14 pull requests Successful merges: - rust-lang/rust#163219 (assumptions_on_binders: Test mixed ambiguous ORs) - rust-lang/rust#164985 (Only recover if we may for `recover_missing_dot`) - rust-lang/rust#161521 (Replace check_attr_crate_level with check_target for #[doc]) - rust-lang/rust#162530 (Move #[naked] attribute check to attribute parsing stage) - rust-lang/rust#164103 (trait solver: Resolve region vars before eager placeholder handling) - rust-lang/rust#164692 (move `ppcf128` lang item to `core::num::imp`) - rust-lang/rust#164702 (Point at `impl` through which associated function is provided) - rust-lang/rust#164741 (Use explicit target cpu in tests parsing generated asm) - rust-lang/rust#164767 (Add regression tests for transmutability issues) - rust-lang/rust#164776 (Account for trait object with implicit `'static` lifetime in field type being returned) - rust-lang/rust#164791 (Self param after const param) - rust-lang/rust#164856 (Switch from `insta` to `expect-test` in bootstrap) - rust-lang/rust#164888 (Add regression tests for #156380) - rust-lang/rust#164967 (Add codegen test for power of two implying nonzero with debuginfo)
| #[note( | ||
| "read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information" | ||
| )] | ||
| pub(crate) struct AttrCrateLevelOnly; |
There was a problem hiding this comment.
This is incorrect, this needs a primary span, otherwise if used as an error it won't have a span to point at and will be displayed like this:
error: this attribute can only be applied at the crate level
|
= note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
(Fixed in #164582)
View all comments
A small change as part of the target checking refactor for #[doc] attribute parsing.
r? @JonathanBrouwer