Skip to content

Commit 5e31876

Browse files
committed
Update documentation for cargo fix --broken-code
This updates the idiom migration section to indicate that `--broken-code` is a flag that can be used to make more progress when fixing code with the idiom lints, and it also more strongly indicates that idiom lints are not ready for prime time and bugs are to be expected. Closes rust-lang/rust#55955
1 parent afef680 commit 5e31876

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/editions/transitioning-an-existing-project-to-a-new-edition.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,24 @@ In Rust 2018, it's considered idiomatic to use the [`dyn`
9292
keyword](../rust-2018/trait-system/dyn-trait-for-trait-objects.html) for
9393
trait objects.
9494

95-
We can ask `cargo fix` to fix it:
95+
We ideally want `cargo fix` to fix all these idioms automatically in the same
96+
manner we did for upgrading to the 2018 edition. **At this point in time,
97+
though, the "idiom lints" are not ready for widespread automatic fixing.** The
98+
compiler isn't making `cargo fix`-compatible suggestions in many cases right
99+
now (and is making incorrect suggestions in others), so enabling the idiom
100+
lints, even with `cargo fix`, is likely to leave your crate with many warnings
101+
still remaining.
102+
103+
It's planned to make these idiom migrations a seamless part of the Rust 2018
104+
experience, but we're not there yet. As a result the following instructions are
105+
recommended only for the intrepid who are willing to work through a few
106+
compiler/Cargo bugs!
107+
108+
With that out of the way, we can instruct Cargo to fix our code snippet with:
96109

97110
```console
98111
$ cargo fix --edition-idioms
99112
```
100-
> The `--edition-idioms` flag applies only to the "current crate" if you want
101-
> to run it against a workspace is necessary to use a workaround with
102-
> `RUSTFLAGS` in order to execute it in all the workspace members.
103-
>
104-
> ```shell
105-
> $ RUSTFLAGS='-Wrust_2018_idioms' cargo fix --all
106-
> ```
107113

108114
Afterwards, `src/lib.rs` looks like this:
109115

@@ -119,4 +125,20 @@ As before, `cargo fix` may not be able to automatically update our code.
119125
If `cargo fix` can't fix something, it will print a warning to the console,
120126
and you'll have to fix it manually.
121127

122-
Enjoy the new edition!
128+
Also as mentioned before, there are known bugs around the idiom lints which
129+
means they're not all ready for prime time yet. This means that you may get a
130+
scary-looking warning to report a bug to Cargo, which happens whenever a fix
131+
proposed by rustc actually caused code to stop compiling by accident. If you'd
132+
like `cargo fix` to make as much progress as possible, even if it causes code to
133+
stop compiling, you can execute:
134+
135+
```console
136+
$ cargo fix --edition-idioms --broken-code
137+
```
138+
139+
This will instruct `cargo fix` to apply changes even if they cause code to stop
140+
compiling, and you'll see the compilation result after all fixes are applied. If
141+
you notice anything awry, please feel free to report an issue to Cargo and we'll
142+
help prioritize and fix it.
143+
144+
Enjoy the new edition!

0 commit comments

Comments
 (0)