Skip to content

Commit 7af4630

Browse files
committed
add a failing test
1 parent d1fb81e commit 7af4630

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ macro_rules! mixed_edition_pat {
99
Some(mut $foo)
1010
};
1111
}
12+
13+
#[macro_export]
14+
macro_rules! bind_ref {
15+
($foo:ident) => {
16+
ref $foo
17+
};
18+
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,9 @@ fn main() {
239239
assert_type_eq(b, &0u32);
240240
assert_type_eq(c, &[0u32]);
241241
assert_type_eq(d, 0u32);
242+
243+
// Test that we use the correct message and suggestion style when pointing inside expansions.
244+
let [migration_lint_macros::bind_ref!(a)] = &[0];
245+
//~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
246+
assert_type_eq(a, &0u32);
242247
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,9 @@ fn main() {
239239
assert_type_eq(b, &0u32);
240240
assert_type_eq(c, &[0u32]);
241241
assert_type_eq(d, 0u32);
242+
243+
// Test that we use the correct message and suggestion style when pointing inside expansions.
244+
let [migration_lint_macros::bind_ref!(a)] = &[0];
245+
//~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
246+
assert_type_eq(a, &0u32);
242247
}

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -562,5 +562,19 @@ help: make the implied reference patterns explicit
562562
LL | let [&Foo(&ref a @ [ref b]), &Foo(&ref c @ [d])] = [&Foo(&[0]); 2];
563563
| + +
564564

565-
error: aborting due to 29 previous errors
565+
error: reference patterns may only be written when the default binding mode is `move`
566+
--> $DIR/migration_lint.rs:244:10
567+
|
568+
LL | let [migration_lint_macros::bind_ref!(a)] = &[0];
569+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ occurs within macro expansion
570+
|
571+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
572+
note: matching on a reference type with a non-reference pattern changes the default binding mode
573+
--> $DIR/migration_lint.rs:244:9
574+
|
575+
LL | let [migration_lint_macros::bind_ref!(a)] = &[0];
576+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
577+
= note: this error originates in the macro `migration_lint_macros::bind_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
578+
579+
error: aborting due to 30 previous errors
566580

0 commit comments

Comments
 (0)