File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed
tests/ui/pattern/rfc-3627-match-ergonomics-2024 Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -562,5 +562,19 @@ help: make the implied reference patterns explicit
562562LL | 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
You can’t perform that action at this time.
0 commit comments