Repository navigation
Move lint validation to attribute parsing - #164918
JonathanBrouwer wants to merge 4 commits into
Conversation
| /// - `custom_tool::blah::bleh` -> `blah::bleh` | ||
| pub lint_name: Symbol, | ||
| /// For example, `single_use_lifetime` is changed to `single_use_lifetimes`. | ||
| pub lint_name_normalized: Symbol, |
There was a problem hiding this comment.
My goal for a follow-up PR is to change this field from a Symbol that needs to be looked up in LintStore to a LintId. I think this should be possible, but encoding and decoding will be a challenge. I think this PR is already a good step forwards regardless.
| pub use attributes::util::{is_builtin_attr, parse_version}; | ||
| pub use context::ShouldEmit; | ||
| pub use diagnostics::ParsedDescription; | ||
| pub use diagnostics::{ParsedDescription, RenamedLintSuggestion, UnknownLintSuggestion}; |
There was a problem hiding this comment.
I'm not sure if people find it cursed to export diagnostic structs such that they can be re-used. I like it
There was a problem hiding this comment.
I don't, it can hide unused diagnostics 😅
There was a problem hiding this comment.
While unused diagnostics are bad, the alternative is duplicating the suggestion structs which risks them diverging when someone edits one but not the other. I think that's worse
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Move lint validation to attribute parsing
|
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_attr_ir
cc @rust-lang/clippy Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
1a9e5b3 to
cb8338e
Compare
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (00e2c28): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @bors rollup=iffy rustc-perf 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 -0.5%, secondary -0.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 0.4%, secondary 0.6%)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: 487.351s -> 486.11s (-0.25%) |
This comment has been minimized.
This comment has been minimized.
cb8338e to
5a6079c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5a6079c to
62ff266
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I don't think this change is correct, it means lowering ast to hir depends on what lints have been registered. Does this mean cargo clippy and cargo check could produce different artefacts? What happens when rust-analyzer decides to implement its own lints? (it's possible, it's a pregistered tool).
Can you talk to people more knowledgeable about this and get them to sign off on this? The people that are working on sharing cargo build caches probably have opinions about this.
@rustbot author
| pub use attributes::util::{is_builtin_attr, parse_version}; | ||
| pub use context::ShouldEmit; | ||
| pub use diagnostics::ParsedDescription; | ||
| pub use diagnostics::{ParsedDescription, RenamedLintSuggestion, UnknownLintSuggestion}; |
There was a problem hiding this comment.
I don't, it can hide unused diagnostics 😅
| // We only want to emit these lints once, on the HIR. | ||
| // On the AST `target_span` will be `DUMMY_SP`, which we use to detect which instance we are. | ||
| // #164898 will fix this, after that PR this check can be removed | ||
| let should_lint = cx.target_span != DUMMY_SP; |
There was a problem hiding this comment.
I don't think this is a good idea:
- I would not accept this as a standalone PR (instead demanding a more rigorous fix)
- Try to keep behavior changes to a minimum during refactors
There was a problem hiding this comment.
This needs to be in this PR because the old code also had similar, though broken, logic through selflint_added_lints. It was broken because it duplicated a lot of diagnostics anyways, which this PR fixes. Emulating the old logic in this PR would be more complicated than just fixing it
I found a slightly more rigorous fix, using parse_filter instead of Span.
I think that should be good enough, since this code is temporary anyways
|
I also don't understand why this ought to block #164607 I still think we should store a |
|
This PR is a breaking change, it now correctly rejects unknown tool lints Consider the following code: macro_rules! wat {
() => {
#[allow(unused_attributes)]
{
#[allow(unregistered_tool::lint)]
println!("boo");
}
};
}
fn main() {
wat!();
}Behavior on current Rust (all channels) With this pr: |
|
Right, that's a fun one I didn't think about! |
This comment has been minimized.
This comment has been minimized.
62ff266 to
417deac
Compare
This comment has been minimized.
This comment has been minimized.
417deac to
cc723c2
Compare
This comment has been minimized.
This comment has been minimized.
I've added an extra check to remove the breaking change from this PR, so we can do it in a follow-up PR instead. Added a test for this I went through all review comments and resolved the ones which were addressed by the latest commit, and left comments on the ones that need further discussion. |
This comment has been minimized.
This comment has been minimized.
cc723c2 to
bbdf8c5
Compare
There was a problem hiding this comment.
Sorry about all the yapping about attributes on macro calls. It's fine to leave it unfixed for now, I do plan to crater a bunch of macro call things Soon(tm), I'll include this in that.
It looks good, I'll take another pass once it's all rebased and stuff.
| cx: &mut AcceptContext<'_, 'a>, | ||
| ) -> Option<(&'a [LintId], Symbol)> { | ||
| let lint_result = cx.sess.lint_store.as_ref().unwrap().check_lint_name( | ||
| // FIXME For historic reasons these checks are not executed on macro calls |
There was a problem hiding this comment.
More precisely, it's only ignored on macro calls produced by another macro's expansion. Prior to macro expansion it's still caught by the pre expansion pass collection.
That is:
macro_rules! identity { ($( $tt:tt )*) => { $( $tt )* } }
fn main() {
#[expect(wat::doesnt_exist)] // ERROR
println!();
identity!{
#[expect(wat::doesnt_exist)] // OK
println!();
}
}I think that's maintained here, as we pass Crate as the pre-expansion target for that. Can you add a test, I don't believe one exists.
There was a problem hiding this comment.
The lint attribute on a plain macro actually doesn't seem to work, because both errors are only produced during late parsing, when cx.target is set accurately.
I tried for a bit to mimic the old behavior, but it doesn't seem to be easy...
bbdf8c5 to
60e801c
Compare
This comment has been minimized.
This comment has been minimized.
We will need the `lint_tools` in the next commits
This is a lot of code being moved around, but not much of the logic changes. I changed some stuff though, so I recommend reviewing the logic side by side.
60e801c to
9d15b14
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.
9d15b14 to
679ce9a
Compare
View all comments
This is an alternative approach to #164607
This can be reviewed commit by commit, each commit passes tests.
My goal is for a follow-up to remove
lint_name_normalizedcompletely and replace it by aLintIdr? @mejrs