Skip to content

Commit beb2a25

Browse files
committed
FIXME: tests for avoiding changes inside expansions
1 parent 998cc72 commit beb2a25

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

tests/ui/pattern/rfc-3627-match-ergonomics-2024/auxiliary/migration_lint_macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ macro_rules! bind_ref {
1616
ref $foo
1717
};
1818
}
19+
20+
#[macro_export]
21+
macro_rules! match_ref {
22+
($p:pat) => {
23+
&$p
24+
};
25+
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed

+10
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,19 @@ fn main() {
243243
//~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
244244
assert_type_eq(a, &0u32);
245245

246+
let &[migration_lint_macros::match_ref!(a)] = &[&0];
247+
//~^ ERROR: reference patterns may only be written when the default binding mode is `move`
248+
assert_type_eq(a, 0u32);
249+
246250
// Test that we use the correct span when labeling a `&` whose subpattern is from an expansion.
251+
// Also test that we don't simplify `&ref x` to `x` when the `ref` is from an expansion.
247252
let &[&migration_lint_macros::bind_ref!(a)] = &[&0];
248253
//~^ ERROR: reference patterns may only be written when the default binding mode is `move` in Rust 2024
249254
//~| WARN: this changes meaning in Rust 2024
250255
assert_type_eq(a, &0u32);
256+
257+
// Test that we don't simplify `&ref x` to `x` when the `&` is from an expansion.
258+
let &[migration_lint_macros::match_ref!(ref a)] = &[&0];
259+
//~^ ERROR: reference patterns may only be written when the default binding mode is `move`
260+
assert_type_eq(a, &0u32);
251261
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs

+10
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,19 @@ fn main() {
243243
//~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
244244
assert_type_eq(a, &0u32);
245245

246+
let [migration_lint_macros::match_ref!(a)] = &[&0];
247+
//~^ ERROR: reference patterns may only be written when the default binding mode is `move`
248+
assert_type_eq(a, 0u32);
249+
246250
// Test that we use the correct span when labeling a `&` whose subpattern is from an expansion.
251+
// Also test that we don't simplify `&ref x` to `x` when the `ref` is from an expansion.
247252
let [&migration_lint_macros::bind_ref!(a)] = &[&0];
248253
//~^ ERROR: reference patterns may only be written when the default binding mode is `move` in Rust 2024
249254
//~| WARN: this changes meaning in Rust 2024
250255
assert_type_eq(a, &0u32);
256+
257+
// Test that we don't simplify `&ref x` to `x` when the `&` is from an expansion.
258+
let [migration_lint_macros::match_ref!(ref a)] = &[&0];
259+
//~^ ERROR: reference patterns may only be written when the default binding mode is `move`
260+
assert_type_eq(a, &0u32);
251261
}

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr

+39-3
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,34 @@ help: make the implied reference pattern explicit
585585
LL | let &[migration_lint_macros::bind_ref!(a)] = &[0];
586586
| +
587587

588+
error: reference patterns may only be written when the default binding mode is `move`
589+
--> $DIR/migration_lint.rs:246:10
590+
|
591+
LL | let [migration_lint_macros::match_ref!(a)] = &[&0];
592+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ occurs within macro expansion
593+
|
594+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
595+
note: matching on a reference type with a non-reference pattern changes the default binding mode
596+
--> $DIR/migration_lint.rs:246:9
597+
|
598+
LL | let [migration_lint_macros::match_ref!(a)] = &[&0];
599+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
600+
= note: this error originates in the macro `migration_lint_macros::match_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
601+
help: make the implied reference pattern explicit
602+
|
603+
LL | let &[migration_lint_macros::match_ref!(a)] = &[&0];
604+
| +
605+
588606
error: reference patterns may only be written when the default binding mode is `move` in Rust 2024
589-
--> $DIR/migration_lint.rs:249:10
607+
--> $DIR/migration_lint.rs:252:10
590608
|
591609
LL | let [&migration_lint_macros::bind_ref!(a)] = &[&0];
592610
| ^ reference pattern not allowed under `ref` default binding mode
593611
|
594612
= warning: this changes meaning in Rust 2024
595613
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
596614
note: matching on a reference type with a non-reference pattern changes the default binding mode
597-
--> $DIR/migration_lint.rs:249:9
615+
--> $DIR/migration_lint.rs:252:9
598616
|
599617
LL | let [&migration_lint_macros::bind_ref!(a)] = &[&0];
600618
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
@@ -603,5 +621,23 @@ help: make the implied reference pattern explicit
603621
LL | let &[&migration_lint_macros::bind_ref!(a)] = &[&0];
604622
| +
605623

606-
error: aborting due to 31 previous errors
624+
error: reference patterns may only be written when the default binding mode is `move`
625+
--> $DIR/migration_lint.rs:258:10
626+
|
627+
LL | let [migration_lint_macros::match_ref!(ref a)] = &[&0];
628+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ occurs within macro expansion
629+
|
630+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
631+
note: matching on a reference type with a non-reference pattern changes the default binding mode
632+
--> $DIR/migration_lint.rs:258:9
633+
|
634+
LL | let [migration_lint_macros::match_ref!(ref a)] = &[&0];
635+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
636+
= note: this error originates in the macro `migration_lint_macros::match_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
637+
help: make the implied reference pattern explicit
638+
|
639+
LL | let &[migration_lint_macros::match_ref!(ref a)] = &[&0];
640+
| +
641+
642+
error: aborting due to 33 previous errors
607643

0 commit comments

Comments
 (0)