Repository navigation
port lint attributes - #162811
port lint attributes#162811mejrs wants to merge 7 commits into
Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer
cc @rust-lang/clippy |
| LL | let y: u32 = (x?).try_into().unwrap(); | ||
| | + +++++++++++++++++++++ |
There was a problem hiding this comment.
Uh yeah I don't know what's happening here
There was a problem hiding this comment.
I think this is minor enough that I'll put it on my todo list as something that we should fix after merging this PR
|
I'll take a look at this on Friday! Thanks for doing this! |
|
Thanks for picking this up ❤️ |
5f087e2 to
c90513f
Compare
|
cc @cjgillot @petrochenkov in case you'd like to take a look (as reviewers of the original pr #155691) |
I'll go ahead and cherrypick some changes from this PR then, some things can be split off. |
|
Blocked on #162813 |
This comment has been minimized.
This comment has been minimized.
c90513f to
5c86bdf
Compare
|
@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.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (837b948): comparison URL. Overall result: ❌✅ regressions and improvements - BENCHMARK(S) FAILEDBenchmarking 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 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 -7.1%, secondary -1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -7.6%, secondary 2.7%)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: 495.925s -> 496.275s (0.07%) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (be9d55c): comparison URL. Overall result: ❌✅ regressions and improvements - 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 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 -2.6%, secondary -3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 4.1%, secondary 4.9%)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.424s -> 491.568s (0.03%) |
|
Perf seems slightly worse than the previous run but it's still positive, and the behavior is more correct now, so let's keep things this way |
There was a problem hiding this comment.
r=me
Thanks so much for all the effort! This has been a lot of work, both from you and @Bryntet
@petrochenkov do you still want to take a look?
@bors rollup=never
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I went through the PR and collected a list of items for follow up PRs. Not all are things we definitely want to do, but at least we can consider them:
|
| #![attr = Feature([fn_delegation#0])] | ||
| extern crate std; | ||
| #[attr = PreludeImport] | ||
| use std::prelude::rust_2021::*; |
There was a problem hiding this comment.
Why did the pretty-printing change, even for things unrelated to lint attributes?
The previous version preserved the relative order of comments and attributes, and the new version does not, so this seems like a regression.
There was a problem hiding this comment.
The relative order is that comments come before unparsed attributes, but there are no longer any unparsed attributes in this file.
See
rust/compiler/rustc_hir_pretty/src/lib.rs
Lines 290 to 302 in 0093837
rust/compiler/rustc_hir_pretty/src/lib.rs
Lines 102 to 130 in 0093837
There was a problem hiding this comment.
(all the other pretty tests already have this regression, this is the only one that had a lint check attribute)
There was a problem hiding this comment.
The relative order is that comments come before unparsed attributes
I don't see any reasons to print parsed and unparsed attributes in different locations, and the unparsed location looks more correct.
But it's not an issue for this PR, if it's pre-existing.
There was a problem hiding this comment.
It has existed since parsed attributes, example:
// comment
#![feature()]hir pretty:
#![attr = Feature([])]
extern crate std;
#[attr = PreludeImport]
use std::prelude::rust_2024::*;
// commentThere was a problem hiding this comment.
It seems that correctly printing comments requires a span, but parsed attributes generally don't have one, so it's not done for the Parsed variant
There was a problem hiding this comment.
It seems that correctly printing comments requires a span, but parsed attributes generally don't have one, so it's not done for the Parsed variant
I see, perhaps it makes sense to do it for parsed attributes that do have a span for other reasons.
There was a problem hiding this comment.
That would make it inconsistent whether comments or crate attributes are printed first 🤔
Having a span for all parsed attributes would also be annoying (aside from the ~decent amount of work), it'd probably increase the size of Attribute/AttributeKind and I'm not sure how to best deal with combined attributes (like multiple repr attributes).
| &format!("{name}::{full_lint_name}") | ||
| } else { | ||
| full_lint_name | ||
| }; |
There was a problem hiding this comment.
Style nit: if let with short arms look better as matches (here and maybe in some other places).
There was a problem hiding this comment.
This is a bit too nitty for me, and while it's a wash to me which style this uses it's not going to last because I'm going to be rewriting this part soon. Next I want to do improvements to reduce the amount of strings that get needlessly allocated around here (this pr already got rid of some).
There was a problem hiding this comment.
Do you strongly care about this? I don't want to do it, personally, but I also don't want to have a debate on it so I'll do it if you want me to.
|
LGTM, most things I had issues with are already listed in #162811 (comment). |
|
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.
Some thoughts on some of them:
with
If macro lints ever happen (in the form of #135432 or smth else) we likely need a tcx to resolve these lints, which cannot be done in attribute parsing
a "downcast_slice" method could also exist in std or e.g. rustc_data_structures.
I think a "just try to parse this without actually erroring" might work (we kinda do this for diagnostic attributes), but it's a bit brittle for my liking, I'm also not sure I like Another option is to force pre-expansion lints to be crate level only (like #163714) but this would also be a lang (new keyword lint) and clippy matter.
|
View all comments
Ports the lint attributes. I've kept this as small as possible, but there is a decent amount of clean up/refactoring that can be done afterwards,
r? @JonathanBrouwer @jdonszelmann
cc @Bryntet