Skip to content

Commit 73ae835

Browse files
committed
Add a section on migrating without Cargo.
1 parent cacf1c4 commit 73ae835

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/editions/advanced-migrations.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ For example, you can use the [`edition2018` annotation][rustdoc-annotation] on t
126126
Another area where the automated fixes cannot apply is if you have a build script which generates Rust code at compile time (see [Code generation] for an example).
127127
In this situation, if you end up with code that doesn't work in the next edition, you will need to manually change the build script to generate code that is compatible.
128128

129+
## Migrating non-Cargo projects
130+
131+
If your project is not using Cargo as a build system, it may still be possible to make use of the automated lints to assist migrating to the next build system.
132+
You can enable the migration lints as described above by enabling the appropriate [lint group].
133+
For example, you can use the `#![warn(rust_2021_compatibility)]` attribute or the `-Wrust-2021-compatibility` [CLI flag].
134+
135+
The next step is to apply those lints to your code.
136+
There are several options here:
137+
138+
* Manually read the warnings and apply the suggestions recommended by the compiler.
139+
* Use an editor or IDE that supports automatically applying suggestions.
140+
For example, [Visual Studio Code] with the [Rust Analyzer extension] has the ability to use the "Quick Fix" links to automatically apply suggestions.
141+
Many other editors and IDEs have similar functionality.
142+
* Write a migration tool using the [`rustfix`] library.
143+
This is the library that Cargo uses internally to take the [JSON messages] from the compiler and modify the source code.
144+
Check the [`examples` directory][rustfix-examples] for examples of how to use the library.
145+
129146
## Writing idiomatic code in a new edition
130147

131148
Editions are not only about new features and removing old ones.
@@ -168,15 +185,21 @@ We're now more idiomatic, and we didn't have to fix our code manually!
168185
[`cargo fix`]: ../../cargo/commands/cargo-fix.html
169186
[`explicit-outlives-requirements`]: ../../rustc/lints/listing/allowed-by-default.html#explicit-outlives-requirements
170187
[`keyword-idents`]: ../../rustc/lints/listing/allowed-by-default.html#keyword-idents
188+
[`rustfix`]: https://github.com/rust-lang/rustfix
171189
[`unused-extern-crates`]: ../../rustc/lints/listing/allowed-by-default.html#unused-extern-crates
172190
[Cargo features]: ../../cargo/reference/features.html
173191
[Cargo package]: ../../cargo/reference/manifest.html#the-package-section
174192
[Cargo targets]: ../../cargo/reference/cargo-targets.html
175193
[Cargo workspace]: ../../cargo/reference/workspaces.html
194+
[CLI flag]: ../../rustc/lints/levels.html#via-compiler-flag
176195
[Code generation]: ../../cargo/reference/build-script-examples.html#code-generation
177196
[conditional compilation]: ../../reference/conditional-compilation.html
178197
[documentation tests]: ../../rustdoc/documentation-tests.html
198+
[JSON messages]: ../../rustc/json.html
179199
[lint group]: ../../rustc/lints/groups.html
180200
[lints]: ../../rustc/lints/index.html
181201
[proc macros]: ../../reference/procedural-macros.html
202+
[Rust Analyzer extension]: https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer
182203
[rustdoc-annotation]: ../../rustdoc/documentation-tests.html#attributes
204+
[rustfix-examples]: https://github.com/rust-lang/rustfix/tree/master/examples
205+
[Visual Studio Code]: https://code.visualstudio.com/

0 commit comments

Comments
 (0)