-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[expect(unused_imports)]
does not work correctly on grouped imports
#127884
Comments
cc @xFrednet who has been handling |
Thank you for the ping. So my educated guess is that this issue comes from how rustc handles group imports. The import from the issue is internally desugared into three separate imports, like this (Playground "Show HIR"): #[expect(unused_imports)]
use ::{};
#[expect(unused_imports)]
use std::io;
#[expect(unused_imports)]
use std::fs; From the text output of HIR it looks like the attributes are duplicated. This in turn creates additional expectations which are not fulfilled. The question is now, hot to figure out, that these items and attributes all originate from the same item. @cjgillot do you maybe have an idea on this one? |
That's not the only place where we duplicate attributes. I had to partially work around it in #127313, but that's not a good solution in general. Right now, the diagnostic infra stores the stable What if we did the other way? I mean:
Step 3 should be ok for incr comp, as Does that make sense to you? |
I'm not sure, I fully understand you. Does this rephrasing sound reasonably close?
|
Yes. |
On what level does Because, if it's on the HIR, we still need to find a way to map from duplicated attributes back to their original single ones. Don't we? |
match id {
Unstable { attr_id, lint_index: Some(lint_index) } => (attr_id, lint_index),
Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
// We are an `eval_always` query, so looking at the attribute's `AttrId` is ok.
let attr_id = tcx.hir().attrs(hir_id)[attr_index].id;
(attr_id, lint_index)
}
_ => bug!(),
} When we duplicate the attributes, we don't change the AttrId, so relying on it is ok. |
Interesting, yep, then this should work :D Is this something that can/should be done with #127313? If we want to make it a followup PR, we should probably ping the reviewer or reroll 🤔 |
Enumerate lint expectations using AttrId This PR implements the idea I outlined in rust-lang#127884 (comment) We can uniquely identify a lint expectation `#[expect(lint0, lint1...)]` using the `AttrId` and the index of the lint inside the attribute. This PR uses this property in `check_expectations`. In addition, this PR stops stashing expected diagnostics to wait for the unstable -> stable `LintExpectationId` mapping: if the lint is emitted with an unstable attribute, it must have been emitted by an `eval_always` query (like inside the resolver), so won't be loaded from cache. Decoding an `AttrId` from the on-disk cache ICEs, so we have no risk of accidentally checking an expectation. Fixes rust-lang#127884 cc `@xFrednet`
Enumerate lint expectations using AttrId This PR implements the idea I outlined in rust-lang#127884 (comment) We can uniquely identify a lint expectation `#[expect(lint0, lint1...)]` using the `AttrId` and the index of the lint inside the attribute. This PR uses this property in `check_expectations`. In addition, this PR stops stashing expected diagnostics to wait for the unstable -> stable `LintExpectationId` mapping: if the lint is emitted with an unstable attribute, it must have been emitted by an `eval_always` query (like inside the resolver), so won't be loaded from cache. Decoding an `AttrId` from the on-disk cache ICEs, so we have no risk of accidentally checking an expectation. Fixes rust-lang#127884 cc `@xFrednet`
Enumerate lint expectations using AttrId This PR implements the idea I outlined in rust-lang/rust#127884 (comment) We can uniquely identify a lint expectation `#[expect(lint0, lint1...)]` using the `AttrId` and the index of the lint inside the attribute. This PR uses this property in `check_expectations`. In addition, this PR stops stashing expected diagnostics to wait for the unstable -> stable `LintExpectationId` mapping: if the lint is emitted with an unstable attribute, it must have been emitted by an `eval_always` query (like inside the resolver), so won't be loaded from cache. Decoding an `AttrId` from the on-disk cache ICEs, so we have no risk of accidentally checking an expectation. Fixes rust-lang/rust#127884 cc `@xFrednet`
Enumerate lint expectations using AttrId This PR implements the idea I outlined in rust-lang/rust#127884 (comment) We can uniquely identify a lint expectation `#[expect(lint0, lint1...)]` using the `AttrId` and the index of the lint inside the attribute. This PR uses this property in `check_expectations`. In addition, this PR stops stashing expected diagnostics to wait for the unstable -> stable `LintExpectationId` mapping: if the lint is emitted with an unstable attribute, it must have been emitted by an `eval_always` query (like inside the resolver), so won't be loaded from cache. Decoding an `AttrId` from the on-disk cache ICEs, so we have no risk of accidentally checking an expectation. Fixes rust-lang/rust#127884 cc `@xFrednet`
the following snippet:
results in the following compiler output:
but removing the
#[expect]
results in:so it is, indeed, supressing the lint - which means the first warning is wrong. it is important to note that the same does not happen on imports of a single item.
rustc version:
The text was updated successfully, but these errors were encountered: