Skip to content

Commit 890abe6

Browse files
committed
Clarify "Migrating macros".
1 parent 02583b6 commit 890abe6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/editions/advanced-migrations.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ You can see the list of lints enabled for each edition in the [lint group] page,
7272
## Migrating macros
7373

7474
Some macros may require manual work to fix them for the next edition.
75-
For example, a macro that generates syntax that only works on the previous edition, then `cargo fix` will not be able to fix it.
75+
For example, `cargo fix --edition` may not be able to automatically fix a macro that generates syntax that does not work in the next edition.
7676

7777
This may be a problem for both [proc macros] and `macro_rules`-style macros.
78-
`macro_rules` macros can be updated if the macro is used within the same crate, but if it is exported with `#[macro_export]`, then it may not be able to fix it.
79-
Proc macros in general cannot be fixed at all.
78+
`macro_rules` macros can sometimes be automatically updated if the macro is used within the same crate, but there are several situations where it cannot.
79+
Proc macros in general cannot be automatically fixed at all.
8080

81-
For example, this (contrived) macro won't get fixed when migrating to 2018.
81+
For example, if we migrate a crate containing this (contrived) macro `foo` from 2015 to 2018, `foo` would not be automatically fixed.
8282

8383
```rust
8484
#[macro_export]
@@ -90,10 +90,15 @@ macro_rules! foo {
9090
}
9191
```
9292

93-
If you don't have any tests that actually call this macro, then `cargo fix --edition` won't display any warnings or errors at all.
94-
However, it won't work when called from another crate.
93+
When this macro is defined in a 2015 crate, it can be used from a crate of any other edition due to macro hygiene (discussed below).
94+
In 2015, `dyn` is a normal identifier and can be used without restriction.
9595

96-
If you have proc macros or exported macros, you are encouraged to test them by importing them in crates from multiple editions.
96+
However, in 2018, `dyn` is no longer a valid identifier.
97+
When using `cargo fix --edition` to migrate to 2018, Cargo won't display any warnings or errors at all.
98+
However, `foo` won't work when called from any crate.
99+
100+
If you have macros, you are encouraged to make sure you have tests that fully cover the macro's syntax.
101+
You may also want to test the macros by importing and using them in crates from multiple editions, just to ensure it works correctly everywhere.
97102
If you run into issues, you'll need to read through the chapters of this guide to understand how the code can be changed to work across all editions.
98103

99104
### Macro hygiene

0 commit comments

Comments
 (0)