Introduce a #[diagnostic::on_unknown] attribute#152901
Introduce a #[diagnostic::on_unknown] attribute#152901rust-bors[bot] merged 3 commits intorust-lang:mainfrom
#[diagnostic::on_unknown] attribute#152901Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
5c63f6f to
a9dd689
Compare
This comment has been minimized.
This comment has been minimized.
a9dd689 to
c87fc9e
Compare
|
I can try this, although I need to read up on how the new infrastructure works and check if it's possible to use this inside of the name resolution stage. Somehow certain things (like lints) act weirdly there. |
|
The attribute refactor is pretty much finished, which means all old style parsers at this point have been removed from the compiler. There are many examples of new-parsing-infrastructure attribute parsers that work at this stage of the compiler (and none more that work using the old system). I don't think I want to accept any new old-style attribute parsers into the compiler anymore for that reason. r? me |
|
@jdonszelmann I can totally understand that you don't want to accept any attributes using the old style. Your comment as currently written is still not useful for me as person that contributes only from time to time to the compiler and doesn't keep up with all the internal changes all the time. I get that I need to change something, but it is really unclear for me:
It's especially not helpful to write that "There are many examples of new-parsing-infrastructure attribute parsers" without even providing a link to one of them. Do you have any documentation or other hints where to get these information from? Otherwise I fear it's impossible for me to satisfy these requests with the limited amount of time I'm able to spend on this change. |
|
Fair enough, take a look at how we handle |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
#151558 has merged now so you can rebase on that.
What need to change exactly
- I think it'll look pretty similar to https://github.com/rust-lang/rust/blob/main/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs
- Add a new variant to https://github.com/rust-lang/rust/blob/main/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs#L28
- I think we should not(?) support formatting parameters like
#[diagnostic::on_unknown_item(message = "{A}{B}{C}"]. To do that either change the logic in https://github.com/rust-lang/rust/blob/main/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs#L287 or fire lints like at https://github.com/rust-lang/rust/blob/main/compiler/rustc_passes/src/check_attr.rs#L630 . I think the former is easier, especially if you want to reject"{Self}"
I have some review comments as well. Thanks for continuing this work by the way :)
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
c87fc9e to
fad08dd
Compare
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_hir/src/attrs |
This comment has been minimized.
This comment has been minimized.
fad08dd to
6319918
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready The new attribute infrastructure is really nice to work with as soon as you get your head around it. Thanks for all the effort that want into it. |
|
This pull request was unapproved due to being closed. |
|
I just would like to apologize for the chaos here. I acknowledge that my wording in the last few comments should have been better. I'm sorry for that, I should have done it better. I still stand to the point that it felt for me like the reviewers are continuously shifting the goal post. |
|
@bors r+ |
…r=jdonszelmann Introduce a `#[diagnostic::on_unknown]` attribute This PR introduces a `#[diagnostic::on_unknown]` attribute that allows crate authors to customize the error messages emitted by unresolved imports. The main usecase for this is using this attribute as part of a proc macro that expects a certain external module structure to exist or certain dependencies to be there. For me personally the motivating use-case are several derives in diesel, that expect to refer to a `tabe` module. That is done either implicitly (via the name of the type with the derive) or explicitly by the user. This attribute would allow us to improve the error message in both cases: * For the implicit case we could explicity call out our assumptions (turning the name into lower case, adding an `s` in the end) + point to the explicit variant as alternative * For the explicit variant we would add additional notes to tell the user why this is happening and what they should look for to fix the problem (be more explicit about certain diesel specific assumptions of the module structure) I assume that similar use-cases exist for other proc-macros as well, therefore I decided to put in the work implementing this new attribute. I would also assume that this is likely not useful for std-lib internal usage. related rust-lang#152900 and rust-lang#128674
…uwer Rollup of 6 pull requests Successful merges: - #152901 (Introduce a `#[diagnostic::on_unknown]` attribute) - #155078 (Reject dangling attributes in where clauses) - #154449 (Invert dependency between `rustc_errors` and `rustc_abi`.) - #154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing) - #154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths) - #155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
Rollup merge of #152901 - weiznich:feature/on_unknown_item, r=jdonszelmann Introduce a `#[diagnostic::on_unknown]` attribute This PR introduces a `#[diagnostic::on_unknown]` attribute that allows crate authors to customize the error messages emitted by unresolved imports. The main usecase for this is using this attribute as part of a proc macro that expects a certain external module structure to exist or certain dependencies to be there. For me personally the motivating use-case are several derives in diesel, that expect to refer to a `tabe` module. That is done either implicitly (via the name of the type with the derive) or explicitly by the user. This attribute would allow us to improve the error message in both cases: * For the implicit case we could explicity call out our assumptions (turning the name into lower case, adding an `s` in the end) + point to the explicit variant as alternative * For the explicit variant we would add additional notes to tell the user why this is happening and what they should look for to fix the problem (be more explicit about certain diesel specific assumptions of the module structure) I assume that similar use-cases exist for other proc-macros as well, therefore I decided to put in the work implementing this new attribute. I would also assume that this is likely not useful for std-lib internal usage. related #152900 and #128674
|
@rust-timer build f6ea057 |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f6ea057): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary -3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 491.232s -> 490.616s (-0.13%) |
|
This causes the regression in #155115 I wonder what caused the regression? The regression is minor enough to probably just accept tho |
Reduce size of `ImportData` Perhaps this will undo the regression caused by rust-lang#152901
…uwer Rollup of 6 pull requests Successful merges: - rust-lang/rust#152901 (Introduce a `#[diagnostic::on_unknown]` attribute) - rust-lang/rust#155078 (Reject dangling attributes in where clauses) - rust-lang/rust#154449 (Invert dependency between `rustc_errors` and `rustc_abi`.) - rust-lang/rust#154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing) - rust-lang/rust#154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths) - rust-lang/rust#155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
View all comments
This PR introduces a
#[diagnostic::on_unknown]attribute that allows crate authors to customize the error messages emitted by unresolved imports. The main usecase for this is using this attribute as part of a proc macro that expects a certain external module structure to exist or certain dependencies to be there.For me personally the motivating use-case are several derives in diesel, that expect to refer to a
tabemodule. That is done either implicitly (via the name of the type with the derive) or explicitly by the user. This attribute would allow us to improve the error message in both cases:sin the end)I assume that similar use-cases exist for other proc-macros as well, therefore I decided to put in the work implementing this new attribute. I would also assume that this is likely not useful for std-lib internal usage.
related #152900 and #128674