Skip to content

Commit 5754a9c

Browse files
Migration lint macro troubles
1 parent ab8be9a commit 5754a9c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

text/3627-match-ergonomics-2024.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,38 @@ rules could require editing the affected patterns twice: once to desugar the
263263
match ergonomics before adopting the new edition, and a second time to restore
264264
match ergonomics after adoption of the new edition.
265265

266+
## Macro subpatterns
267+
268+
Unfortunately, when a subpattern derives from a macro expansion, fully
269+
desugaring the match ergonomics may not be possible. For example:
270+
271+
```rust
272+
//! crate foo (edition 2021)
273+
#[macro_export]
274+
macro_rules! foo {
275+
($foo:ident) => {
276+
[$foo]
277+
};
278+
}
279+
```
280+
281+
```rust
282+
//! crate bar (edition 2021, want to migrate to 2024)
283+
extern crate foo;
284+
use foo::*;
285+
286+
fn main() {
287+
let [[&x], foo!(y)] = &[[&0], [0]];
288+
//~^ WARN: the semantics of this pattern will change in edition 2024
289+
let _: i32 = x;
290+
let _: &i32 = y;
291+
}
292+
```
293+
294+
In such cases, there is no possible machine-applicable suggstion we could emit
295+
to produce code compatible with all editions (short of expanding the macro).
296+
However, such code should be extremely rare in practice.
297+
266298
# Drawbacks
267299
[drawbacks]: #drawbacks
268300

0 commit comments

Comments
 (0)