-
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
Enforce alphabetical sorting with tidy #102719
Conversation
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This is nice. My only thought here is that, because it's a very manual annotation, it will be forgotten. Is there any way we could maybe even get rid of the "end" annotation? |
I agree, but seeing how this has tidied up some sorting errors already, it's hard to argue this isn't a step forward.
Don't know if we want to get this advanced, but there are places in ui tests where we use regular expressions. The begin comment could contain a regular expression, then sort all nonempty lines that match that, perhaps sorting by a capture group. The downside would be that any change which causes one line to not match (like a comment in the middle of an argument list) would cause the elements below to not be sorted. So maybe we want a way to diagnose that... But now we're talking about tooling for the tools. Maybe a simple end delimiter is better. |
I mean, we could be a bit stricter and put all the items that we want to be in alphabetical order in their own block, then annotate that block. |
What about making rustfmt works with feature attributes? |
Could you add this annotatation here as well? rust/compiler/rustc_error_messages/src/lib.rs Lines 37 to 66 in 4bd3078
|
Seeing |
4b8a1a2
to
2b38a33
Compare
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki |
I think we could get rid of the end annotation with more heuristics, but I think it's quite complex already and I don't think the end annotation is particularly annoying, so I'd rather not do this. Our best chance for not forgetting to add it to new places is to use it in enough places so that many people become aware of it, and then the assigned reviewer or people that randomly come across can remind the author of this. I'll also ping @nnethercote here since you've been adding a lot of size assertions which are particularly impacted by this. |
|
This is great. A+, 10/10, would recommend. Can you use it for dependencies in I agree the |
It will complain about lines after the section not being sorted (unless you do this at the end of the file, in which case it will probably work) |
Could it be made to complain if it reaches either the end of file or another start annotation, without hitting an intervening end annotation? |
I can implement this tomorrow, yes. I could also add it to all the Cargo.toml but I'd rather not do this right now. I think it should check those implicitly, which takes some more code, which I'd rather do in a follow up PR. The big diff in the unstable options is making me feel very uneasy and I'd like to see this merged rather soon :D |
Oh, and I just noticed that I have a bad typo in the commit message, it should be "directive" |
I implemented that error message and CI is green now |
☔ The latest upstream changes (presumably #102926) made this pull request unmergeable. Please resolve the merge conflicts. |
It can be used to ensure that a list of things is sorted alphabetically. It goes off lines, but contains several heuristics to work with normal Rust code (looking at indentation, ignoring comments and attributes).
0dc87bc
to
ce35609
Compare
Thank you @Dylan-DPC for doing the rebase as I requested, as I can't do it right now and would like to get this merged quickly |
@bors r+ |
Rollup of 7 pull requests Successful merges: - rust-lang#102623 (translation: eager translation) - rust-lang#102719 (Enforce alphabetical sorting with tidy) - rust-lang#102830 (Unify `tcx.constness` query and param env constness checks) - rust-lang#102883 (Fix stabilization of `feature(half_open_range_patterns)`) - rust-lang#102927 (Fix `let` keyword removal suggestion in structs) - rust-lang#102936 (rustdoc: remove unused CSS `nav.sum`) - rust-lang#102940 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Great to have this available and checked in CI! I would love to see this available in rustfmt, as an attribute on a block or declaration. |
Rollup of 7 pull requests Successful merges: - rust-lang#102623 (translation: eager translation) - rust-lang#102719 (Enforce alphabetical sorting with tidy) - rust-lang#102830 (Unify `tcx.constness` query and param env constness checks) - rust-lang#102883 (Fix stabilization of `feature(half_open_range_patterns)`) - rust-lang#102927 (Fix `let` keyword removal suggestion in structs) - rust-lang#102936 (rustdoc: remove unused CSS `nav.sum`) - rust-lang#102940 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
We have many places where things are supposed to be sorted alphabetically. For the smaller and more recent size assertions, this is mostly upheld, but in other more... alive places it's very messy.
This introduces a new tidy directive to check that a section of code is sorted alphabetically and fixes all places where sorting has gone wrong.