Skip to content

Commit 3710b0c

Browse files
authored
Merge pull request #263 from rylev/cleanup
Add more consistent headings and add a migration section to reserving-syntax
2 parents 36f7292 + a95e38a commit 3710b0c

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src/rust-2021/disjoint-capture-in-closures.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ Starting in Rust 2021, closures captures are more precise. Typically they will o
2828

2929
Disjoint capture was proposed as part of [RFC 2229](https://github.com/rust-lang/rfcs/blob/master/text/2229-capture-disjoint-fields.md) and the RFC contains details about the motivation.
3030

31-
## Migrating to Rust 2021
31+
## Migration
32+
33+
As a part of the 2021 edition a migration lint, `rust_2021_incompatible_closure_captures`, has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
34+
35+
In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run:
36+
37+
```sh
38+
cargo fix --edition
39+
```
40+
41+
Below is an examination of how to manually migrate code to use closure captures that are compatible with Rust 2021 should the automatic migration fail
42+
or you would like to better understand how the migration works.
3243

3344
Changing the variables captured by a closure can cause programs to change behavior or to stop compiling in two cases:
3445

src/rust-2021/or-patterns-macro-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ It's important to remember that editions are _per crate_, so the only relevant e
3434
of the crate where the macro is defined. The edition of the crate where the macro is used does not
3535
change how the macro works.
3636

37-
## Migration to Rust 2021
37+
## Migration
3838

3939
A lint, `rust_2021_incompatible_or_patterns`, gets triggered whenever there is a use `$_:pat` which
4040
will change meaning in Rust 2021.

src/rust-2021/prelude.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ It's identical to the current one, except for three new additions:
3232

3333
The tracking issue [can be found here](https://github.com/rust-lang/rust/issues/85684).
3434

35-
## Migration to Rust 2021
35+
## Migration
3636

3737
As a part of the 2021 edition a migration lint, `rust_2021_prelude_collisions`, has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
3838

src/rust-2021/reserving-syntax.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,36 @@ committed to any of them yet):
5050
- `c""` or `z""` for null-terminated C strings.
5151

5252
[10]: https://github.com/rust-lang/rfcs/pull/3101
53+
54+
55+
## Migration
56+
57+
As a part of the 2021 edition a migration lint, `rust_2021_prefixes_incompatible_syntax`, has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
58+
59+
In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run:
60+
61+
```sh
62+
cargo fix --edition
63+
```
64+
65+
Should you want or need to manually migrate your code, migration is fairly straight-forward.
66+
67+
Let's say you have a macro that is defined like so:
68+
69+
```rust
70+
macro_rules! my_macro {
71+
($a:tt $b:tt) => {};
72+
}
73+
```
74+
75+
In Rust 2015 and 2018 it's legal for this macro to be called like so with no space between the first token tree and the second:
76+
77+
```rust,ignore
78+
my_macro!(z"hey");
79+
```
80+
81+
This `z` prefix is no longer allowed in Rust 2021, so in order to call this macro, you must add a space after the prefix like so:
82+
83+
```rust,ignore
84+
my_macro!(z "hey");
85+
```

0 commit comments

Comments
 (0)