* `--edition` always means "next" edition.
* `--edition` when on the most recent edition is not an error, just a warning.
* Support fix to 2021 edition.
What was previously "Fixing" was a message for after the fixes had
been applied. I think it would be clearer if it said "Fixed",
to indicate that the fixes had actually finished.
The new "Fixing" is posted just before it starts. This is verbose-only
since it is a little noisy.
There shouldn't be any functional changes here.
* Some doc comments.
* Construct `FixArgs` at once so it doesn't need to bother with unnecessary Options.
* Remove IdiomEditionMismatch, it is not used.
* Use a general deduping mechanism for fix messages.
The `anyhow` crate interoperates with the `std::error::Error` trait
rather than a custom `Fail` trait, and this is the general trend of
error handling in Rust as well.
Note that this is mostly mechanical (sed) and intended to get the test
suite passing. As usual there's still more idiomatic cleanup that can
happen, but that's left to later commits.
I originally opted to report bugs to Cargo instead of Rust because I was
afraid of the implementation of `cargo fix` itself. These seem to all be
weeded out now (largely at least), and the overwhelming majority of bugs
are now rust-lang/rust suggestion bugs. Let's suggest reporting bugs
directly there!
It can be difficult to figure out what's wrong when a user reports that
`cargo fix` fails. There's often a large list of warnings, and it can
be hard to figure out which one caused a compile error.
This, like `--prepare-for`, will be part of the transition guide which
automatically applies the necessary lint group from the compiler to associated
code.
The `--edition-idioms` flag does not take an argument and will automatically
enable the right lint group based on the edition being compiled for.
cc #52679
This commit updates the `cargo fix` implementation to iteratively apply fixes
from the compiler instead of only once. Currently the compiler can sometimes
emit overlapping suggestions, such as in the case of transitioning
::foo::<::Bar>();
to ...
crate::foo::<crate::Bar>();
and `rustfix` rightfully can't handle overlapping suggestions as there's no
clear way of how to disambiguate the fixes. To fix this problem Cargo will now
run `rustc` and `rustfix` multiple times, attempting to reach a steady state
where no fixes failed to apply.
Naturally this is a pretty tricky thing to do and we want to be sure that Cargo
doesn't loop forever, for example. A number of safeguards are in place to
prevent Cargo from going off into the weeds when fixing files, notably avoiding
to reattempt fixes if no successful fixes ended up being applied.
Closes#5813Closesrust-lang/rust#52754
This commit adds two diagnostics in particular to ease the transition into the
2018 edition. The current transition process is pretty particular and must be
done carefully, so let's try to automate things to make it as painless as
possible! Notably the new diagnostics are:
* If you `cargo fix --prepare-for 2018` a crate which already has the 2018
edition enabled, then an error is generated. This is because the compiler
can't prepare for the 2018 edition if you're already in the 2018 edition, the
lints won't have a chance to fire. You can only execute `--prepare-for 2018`
over crates in the 2015 edition.
* If you `cargo fix --prepare-for 2018` and have forgotten the
`rust_2018_preview` feature, a warning is issued. The lints don't fire unless
the feature is enabled, so this is intended to warn in this situation to
ensure that lints fire as much as they can.
After this commit if `cargo fix --prepare-for` exits successfully with zero
warnings then crates should be guaranteed to be compatible!
Closes#5778
This commit imports the `cargo fix` subcommand in rust-lang-nursery/rustfix
directly into Cargo as a subcommand. This should allow us to ease our
distribution story of `cargo fix` as we prepare for the upcoming 2018 edition
release.
It's been attempted here to make the code as idiomatic as possible for Cargo's
own codebase. Additionally all tests from cargo-fix were imported into Cargo's
test suite as well. After this lands and is published in nightly the `cargo-fix`
command in rust-lang-nursery/rustfix will likely be removed.
cc rust-lang/rust#52272