Introduce a #[diagnostic::on_unknown] attribute#152901
Introduce a #[diagnostic::on_unknown] attribute#152901weiznich wants to merge 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 :)
tests/ui/diagnostic_namespace/on_unknown_item/unknown_import.rs
Outdated
Show resolved
Hide resolved
|
@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 comment has been minimized.
This comment has been minimized.
1358b98 to
c0fcdda
Compare
This comment has been minimized.
This comment has been minimized.
There hasn't been engagement with this, nor do I have an alternative that I really like. My main dislike with it is that's on the longer side. @jdonszelmann I propose we drop the "item" part, so just |
|
I think I quite like |
This comment has been minimized.
This comment has been minimized.
|
@rustbot author |
There was a problem hiding this comment.
I made some changes to the Directive api (see #154858). When you rebase please drop the FormatString::format and args -> Some(args) changes...
| let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),); | ||
|
|
||
| let mut diag = struct_span_code_err!(self.dcx(), span, E0432, "{msg}"); | ||
| let default_message = |
There was a problem hiding this comment.
...and here you'll need to do something like this:
let args = FormatArgs {
this: paths.join(", ").collect(),
// Unused
this_sugared: String::new(),
// Unused
item_context: "",
// Unused
generic_args: Vec::new(),
};
let CustomDiagnostic { message, label, notes, parent_label: _ } = directive.eval(None, &args);c0fcdda to
d65526f
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. |
This comment has been minimized.
This comment has been minimized.
d65526f to
a23ba50
Compare
| pub enum FormatWarning { | ||
| PositionalArgument { span: Span, help: String }, | ||
| InvalidSpecifier { name: String, span: Span }, | ||
| DisallowedPlaceholder { span: Span }, |
There was a problem hiding this comment.
This enum variant is never constructed.
One of your previous commits had
+ if matches!(mode, Mode::DiagnosticOnUnknownItem) {
+ warnings.push(FormatWarning::DisallowedPlaceholder { span });
+ }but I cannot find it anymore; you may have accidentally dropped it.
Please put this in the match in fn parse_arg and make it return FormatArg::AsIs. And add a test for it (idk if you had one, maybe it was also dropped?).
|
I do not have much capacity or motivation left to do yet another set of changes on top of this. |
|
I'm sorry to hear that. I definitely understand the frustration as this part of the codebase is also very merge conflict prone. I still really want to see this happen, would you mind if I continue your work in the future? |
|
To clarify that again: The main point of frustration is not resolving the merge conflicts. The main point of frustration is that it feels you you as reviewer continuously shift the goal post on this by bringing up yet another thing that was there from the beginning and now suddenly needs to be changed. That in combination with out of my perspective delayed reviews and resolutions to open questions + merge conflicts from changes by exactly these reviews that delay the review in favor of the their changes make it very painful to continue working on this. It just feels disrespectful and especially not welcome to me. And to be extra clear: The question about the naming was open for more than 4 weeks with noone on the reviewers side even seem to care about it more than "that name doesn't sound perfect". You certainly can do such a thing, but please respect that at some point people just walk away and stop trying to contribute at all. I'm still open to consider finishing that at some point, but at this point that would require a honest, final list of what still needs to be done that doesn't contain yet another rewrite. Also at least acknowledging that you (not as person but as reviewers) could have done better might help with the motivation. |
This PR introduces a `#[diagnostic::on_unknown_item]` 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.
#[diagnostic::on_unknown_item] attribute#[diagnostic::on_unknown] attribute
a23ba50 to
93f9aec
Compare
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