From b8615aa3f5cde84aa7277e549c2a30fa5e4ac5d5 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 24 Sep 2024 11:32:33 +0200 Subject: [PATCH 1/7] Move existing rfc3627 tests to a dedicated folder --- .../auxiliary/migration_lint_macros.rs} | 0 .../migration_lint.fixed} | 6 ++-- .../migration_lint.rs} | 6 ++-- .../migration_lint.stderr} | 30 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) rename tests/ui/pattern/{auxiliary/match_ergonomics_2024_macros.rs => rfc-3627-match-ergonomics-2024/auxiliary/migration_lint_macros.rs} (100%) rename tests/ui/pattern/{match_ergonomics_2024.fixed => rfc-3627-match-ergonomics-2024/migration_lint.fixed} (91%) rename tests/ui/pattern/{match_ergonomics_2024.rs => rfc-3627-match-ergonomics-2024/migration_lint.rs} (91%) rename tests/ui/pattern/{match_ergonomics_2024.stderr => rfc-3627-match-ergonomics-2024/migration_lint.stderr} (80%) diff --git a/tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/auxiliary/migration_lint_macros.rs similarity index 100% rename from tests/ui/pattern/auxiliary/match_ergonomics_2024_macros.rs rename to tests/ui/pattern/rfc-3627-match-ergonomics-2024/auxiliary/migration_lint_macros.rs diff --git a/tests/ui/pattern/match_ergonomics_2024.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed similarity index 91% rename from tests/ui/pattern/match_ergonomics_2024.fixed rename to tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index 1ec2b5a214bfa..253c9589a552a 100644 --- a/tests/ui/pattern/match_ergonomics_2024.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -1,12 +1,12 @@ //@ edition: 2021 //@ run-rustfix //@ rustfix-only-machine-applicable -//@ aux-build:match_ergonomics_2024_macros.rs +//@ aux-build:migration_lint_macros.rs #![feature(mut_ref, ref_pat_eat_one_layer_2024)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] -extern crate match_ergonomics_2024_macros; +extern crate migration_lint_macros; struct Foo(u8); @@ -47,7 +47,7 @@ fn main() { match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. - (Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => { + (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { //~^ WARN: the semantics of this pattern will change in edition 2024 _x = 4; _y = &7; diff --git a/tests/ui/pattern/match_ergonomics_2024.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs similarity index 91% rename from tests/ui/pattern/match_ergonomics_2024.rs rename to tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index c9f992c12d4a2..1406db779cc7b 100644 --- a/tests/ui/pattern/match_ergonomics_2024.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -1,12 +1,12 @@ //@ edition: 2021 //@ run-rustfix //@ rustfix-only-machine-applicable -//@ aux-build:match_ergonomics_2024_macros.rs +//@ aux-build:migration_lint_macros.rs #![feature(mut_ref, ref_pat_eat_one_layer_2024)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] -extern crate match_ergonomics_2024_macros; +extern crate migration_lint_macros; struct Foo(u8); @@ -47,7 +47,7 @@ fn main() { match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. - (Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => { + (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { //~^ WARN: the semantics of this pattern will change in edition 2024 _x = 4; _y = &7; diff --git a/tests/ui/pattern/match_ergonomics_2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr similarity index 80% rename from tests/ui/pattern/match_ergonomics_2024.stderr rename to tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index 11844434ad214..4d7230120247d 100644 --- a/tests/ui/pattern/match_ergonomics_2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -1,5 +1,5 @@ error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:14:9 + --> $DIR/migration_lint.rs:14:9 | LL | let Foo(mut a) = &Foo(0); | -^^^^^^^^^ @@ -7,13 +7,13 @@ LL | let Foo(mut a) = &Foo(0); | help: desugar the match ergonomics: `&` | note: the lint level is defined here - --> $DIR/match_ergonomics_2024.rs:7:9 + --> $DIR/migration_lint.rs:7:9 | LL | #![deny(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:18:9 + --> $DIR/migration_lint.rs:18:9 | LL | let Foo(mut a) = &mut Foo(0); | -^^^^^^^^^ @@ -21,7 +21,7 @@ LL | let Foo(mut a) = &mut Foo(0); | help: desugar the match ergonomics: `&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:22:12 + --> $DIR/migration_lint.rs:22:12 | LL | if let Some(&_) = &&&&&Some(&0u8) {} | -^^^^^^^ @@ -29,7 +29,7 @@ LL | if let Some(&_) = &&&&&Some(&0u8) {} | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:25:12 + --> $DIR/migration_lint.rs:25:12 | LL | if let Some(&mut _) = &&&&&Some(&mut 0u8) {} | -^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | if let Some(&mut _) = &&&&&Some(&mut 0u8) {} | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:28:12 + --> $DIR/migration_lint.rs:28:12 | LL | if let Some(&_) = &&&&&mut Some(&0u8) {} | -^^^^^^^ @@ -45,7 +45,7 @@ LL | if let Some(&_) = &&&&&mut Some(&0u8) {} | help: desugar the match ergonomics: `&&&&&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:31:12 + --> $DIR/migration_lint.rs:31:12 | LL | if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +56,7 @@ LL | if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut So | ++++ ++++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:34:12 + --> $DIR/migration_lint.rs:34:12 | LL | if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Som | ++++ ++++ +++++++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:43:9 + --> $DIR/migration_lint.rs:43:9 | LL | let Struct { a, mut b, c } = &s; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -78,20 +78,20 @@ LL | let &Struct { ref a, mut b, ref c } = &s; | + +++ +++ warning: the semantics of this pattern will change in edition 2024 - --> $DIR/match_ergonomics_2024.rs:50:9 + --> $DIR/migration_lint.rs:50:9 | -LL | (Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(_y)) => { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/match_ergonomics_2024.rs:46:12 + --> $DIR/migration_lint.rs:46:12 | LL | #[warn(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: desugar the match ergonomics | -LL | &(Some(mut _x), match_ergonomics_2024_macros::mixed_edition_pat!(ref _y)) => { - | + +++ +LL | &(Some(mut _x), migration_lint_macros::mixed_edition_pat!(ref _y)) => { + | + +++ error: aborting due to 8 previous errors; 1 warning emitted From c22588b700a62a1d93ff7bc30fd49583efab4ad2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 20 Sep 2024 19:47:30 +0200 Subject: [PATCH 2/7] Add `min_match_ergonomics_2024` feature gate --- compiler/rustc_feature/src/unstable.rs | 3 +++ compiler/rustc_span/src/symbol.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index fa3a7049f4a07..5fff81d3e1cd7 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -516,6 +516,9 @@ declare_features! ( (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), + /// A very restricted form of match ergonomics used over the 2024 edition transition to give + /// more time for T-lang to decide the final form of RFC3627. + (incomplete, min_match_ergonomics_2024, "CURRENT_RUSTC_VERSION", Some(123076)), /// A minimal, sound subset of specialization intended to be used by the /// standard library until the soundness issues with specialization /// are fixed. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 402232a1720b7..81ae66ccf6807 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1218,6 +1218,7 @@ symbols! { min_const_generics, min_const_unsafe_fn, min_exhaustive_patterns, + min_match_ergonomics_2024, min_specialization, min_type_alias_impl_trait, minnumf128, From 4abbdfa1c9cd3e2f3181608fb60539755f3a8068 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 6 Oct 2024 20:05:27 +0200 Subject: [PATCH 3/7] Prepare tests --- .../migration_lint.fixed | 111 ++++++++++++++---- .../migration_lint.rs | 111 ++++++++++++++---- .../migration_lint.stderr | 105 ++++++++++++----- 3 files changed, 256 insertions(+), 71 deletions(-) diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index 253c9589a552a..528d274c0ac2a 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -8,49 +8,120 @@ extern crate migration_lint_macros; -struct Foo(u8); +struct Foo(T); + +// Tests type equality in a way that avoids coercing `&&T` to `&T`. +trait Eq {} +impl Eq for T {} +fn assert_type_eq>(_: T, _: U) {} fn main() { - let &Foo(mut a) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 - a = 42; + let Foo(x) = &Foo(0); + assert_type_eq(x, &0u8); + + let Foo(x) = &mut Foo(0); + assert_type_eq(x, &mut 0u8); - let &mut Foo(mut a) = &mut Foo(0); + let &Foo(mut x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 - a = 42; + assert_type_eq(x, 0u8); - if let &&&&&Some(&_) = &&&&&Some(&0u8) {} + let &mut Foo(mut x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + + let Foo(ref x) = &Foo(0); + assert_type_eq(x, &0u8); + + let Foo(ref x) = &mut Foo(0); + assert_type_eq(x, &0u8); + + let &Foo(x) = &Foo(0); + assert_type_eq(x, 0u8); - if let &&&&&Some(&mut _) = &&&&&Some(&mut 0u8) {} + let &mut Foo(x) = &mut Foo(0); + assert_type_eq(x, 0u8); + + let &Foo(x) = &Foo(&0); + assert_type_eq(x, &0u8); + + let &mut Foo(x) = &mut Foo(&0); + assert_type_eq(x, &0u8); + + let &Foo(&x) = &Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let &&&&&mut Some(&_) = &&&&&mut Some(&0u8) {} + let &Foo(&mut x) = &Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} + let &mut Foo(&x) = &mut Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {} + let &mut Foo(&mut x) = &mut Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + + if let Some(x) = &&&&&Some(&0u8) { + assert_type_eq(x, &&0u8); + } + + if let &&&&&Some(&x) = &&&&&Some(&0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, &mut 0u8); + } - struct Struct { - a: u32, - b: u32, - c: u32, + struct Struct { + a: A, + b: B, + c: C, } - let s = Struct { a: 0, b: 0, c: 0 }; - let &Struct { ref a, mut b, ref c } = &s; + + let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(a, &0u32); + assert_type_eq(b, 0u32); + + let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(a, 0u32); + assert_type_eq(b, &&0u32); + assert_type_eq(c, &&0u32); + + if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = + //~^ ERROR: the semantics of this pattern will change in edition 2024 + &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) + { + assert_type_eq(a, &0u32); + assert_type_eq(b, 0u32); + assert_type_eq(c, &&0u32); + } #[warn(rust_2024_incompatible_pat)] match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. - (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { + (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { //~^ WARN: the semantics of this pattern will change in edition 2024 - _x = 4; - _y = &7; + assert_type_eq(x, 0u32); + assert_type_eq(y, &0u32); } _ => {} } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index 1406db779cc7b..0c5be2c761d16 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -8,49 +8,120 @@ extern crate migration_lint_macros; -struct Foo(u8); +struct Foo(T); + +// Tests type equality in a way that avoids coercing `&&T` to `&T`. +trait Eq {} +impl Eq for T {} +fn assert_type_eq>(_: T, _: U) {} fn main() { - let Foo(mut a) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 - a = 42; + let Foo(x) = &Foo(0); + assert_type_eq(x, &0u8); + + let Foo(x) = &mut Foo(0); + assert_type_eq(x, &mut 0u8); - let Foo(mut a) = &mut Foo(0); + let Foo(mut x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 - a = 42; + assert_type_eq(x, 0u8); - if let Some(&_) = &&&&&Some(&0u8) {} + let Foo(mut x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + + let Foo(ref x) = &Foo(0); + assert_type_eq(x, &0u8); + + let Foo(ref x) = &mut Foo(0); + assert_type_eq(x, &0u8); + + let &Foo(x) = &Foo(0); + assert_type_eq(x, 0u8); - if let Some(&mut _) = &&&&&Some(&mut 0u8) {} + let &mut Foo(x) = &mut Foo(0); + assert_type_eq(x, 0u8); + + let &Foo(x) = &Foo(&0); + assert_type_eq(x, &0u8); + + let &mut Foo(x) = &mut Foo(&0); + assert_type_eq(x, &0u8); + + let Foo(&x) = &Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let Some(&_) = &&&&&mut Some(&0u8) {} + let Foo(&mut x) = &Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} + let Foo(&x) = &mut Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); - if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {} + let Foo(&mut x) = &mut Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + + if let Some(x) = &&&&&Some(&0u8) { + assert_type_eq(x, &&0u8); + } + + if let Some(&x) = &&&&&Some(&0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let Some(&mut x) = &&&&&Some(&mut 0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let Some(&x) = &&&&&mut Some(&0u8) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, 0u8); + } + + if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(x, &mut 0u8); + } - struct Struct { - a: u32, - b: u32, - c: u32, + struct Struct { + a: A, + b: B, + c: C, } - let s = Struct { a: 0, b: 0, c: 0 }; - let Struct { a, mut b, c } = &s; + + let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; + //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(a, &0u32); + assert_type_eq(b, 0u32); + + let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + assert_type_eq(a, 0u32); + assert_type_eq(b, &&0u32); + assert_type_eq(c, &&0u32); + + if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = + //~^ ERROR: the semantics of this pattern will change in edition 2024 + &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) + { + assert_type_eq(a, &0u32); + assert_type_eq(b, 0u32); + assert_type_eq(c, &&0u32); + } #[warn(rust_2024_incompatible_pat)] match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. - (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { + (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { //~^ WARN: the semantics of this pattern will change in edition 2024 - _x = 4; - _y = &7; + assert_type_eq(x, 0u32); + assert_type_eq(y, &0u32); } _ => {} } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index 4d7230120247d..29e9183acc3be 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -1,7 +1,7 @@ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:14:9 + --> $DIR/migration_lint.rs:25:9 | -LL | let Foo(mut a) = &Foo(0); +LL | let Foo(mut x) = &Foo(0); | -^^^^^^^^^ | | | help: desugar the match ergonomics: `&` @@ -13,85 +13,128 @@ LL | #![deny(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:18:9 + --> $DIR/migration_lint.rs:29:9 | -LL | let Foo(mut a) = &mut Foo(0); +LL | let Foo(mut x) = &mut Foo(0); | -^^^^^^^^^ | | | help: desugar the match ergonomics: `&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:22:12 + --> $DIR/migration_lint.rs:51:9 | -LL | if let Some(&_) = &&&&&Some(&0u8) {} +LL | let Foo(&x) = &Foo(&0); + | -^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:55:9 + | +LL | let Foo(&mut x) = &Foo(&mut 0); + | -^^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:59:9 + | +LL | let Foo(&x) = &mut Foo(&0); + | -^^^^^^ + | | + | help: desugar the match ergonomics: `&mut` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:63:9 + | +LL | let Foo(&mut x) = &mut Foo(&mut 0); + | -^^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&mut` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:71:12 + | +LL | if let Some(&x) = &&&&&Some(&0u8) { | -^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:25:12 + --> $DIR/migration_lint.rs:76:12 | -LL | if let Some(&mut _) = &&&&&Some(&mut 0u8) {} +LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { | -^^^^^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:28:12 + --> $DIR/migration_lint.rs:81:12 | -LL | if let Some(&_) = &&&&&mut Some(&0u8) {} +LL | if let Some(&x) = &&&&&mut Some(&0u8) { | -^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:31:12 + --> $DIR/migration_lint.rs:86:12 | -LL | if let Some(&mut Some(Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} +LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: desugar the match ergonomics | -LL | if let &mut Some(&mut Some(&mut Some(_))) = &mut Some(&mut Some(&mut Some(0u8))) {} - | ++++ ++++ +LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { + | ++++ ++++ +++++++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:34:12 + --> $DIR/migration_lint.rs:97:9 | -LL | if let Some(&mut Some(Some(_a))) = &mut Some(&mut Some(&mut Some(0u8))) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; + | ^^^^^^^^^^^^^^^^^^^^^^ | help: desugar the match ergonomics | -LL | if let &mut Some(&mut Some(&mut Some(ref mut _a))) = &mut Some(&mut Some(&mut Some(0u8))) {} - | ++++ ++++ +++++++ +LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; + | + +++ +++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:43:9 + --> $DIR/migration_lint.rs:102:9 | -LL | let Struct { a, mut b, c } = &s; - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: desugar the match ergonomics | -LL | let &Struct { ref a, mut b, ref c } = &s; - | + +++ +++ +LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; + | + +++ + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:108:12 + | +LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: desugar the match ergonomics + | +LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = + | + + + +++ warning: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:50:9 + --> $DIR/migration_lint.rs:121:9 | -LL | (Some(mut _x), migration_lint_macros::mixed_edition_pat!(_y)) => { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/migration_lint.rs:46:12 + --> $DIR/migration_lint.rs:117:12 | LL | #[warn(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: desugar the match ergonomics | -LL | &(Some(mut _x), migration_lint_macros::mixed_edition_pat!(ref _y)) => { - | + +++ +LL | &(Some(mut x), migration_lint_macros::mixed_edition_pat!(ref y)) => { + | + +++ -error: aborting due to 8 previous errors; 1 warning emitted +error: aborting due to 13 previous errors; 1 warning emitted From 4107322766523afa7d1968acc0dfee4fd06e8ad8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 6 Oct 2024 20:47:06 +0200 Subject: [PATCH 4/7] Error on resetted binding mode in edition 2024 --- compiler/rustc_hir_typeck/src/pat.rs | 15 +- compiler/rustc_hir_typeck/src/writeback.rs | 6 +- compiler/rustc_lint_defs/src/builtin.rs | 4 +- .../rustc_middle/src/ty/typeck_results.rs | 15 +- compiler/rustc_mir_build/src/errors.rs | 2 + .../rustc_mir_build/src/thir/pattern/mod.rs | 28 +++- .../migration_lint.fixed | 9 +- .../migration_lint.rs | 7 +- .../migration_lint.stderr | 20 +-- .../min_match_ergonomics_fail.rs | 49 ++++++ .../min_match_ergonomics_fail.stderr | 144 ++++++++++++++++++ .../min_match_ergonomics_success.rs | 19 +++ 12 files changed, 270 insertions(+), 48 deletions(-) create mode 100644 tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs create mode 100644 tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr create mode 100644 tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 45a6efc7a6a32..8eb3118fb8ad8 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -692,10 +692,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { BindingMode(def_br, Mutability::Mut) } else { // `mut` resets binding mode on edition <= 2021 - self.typeck_results + *self + .typeck_results .borrow_mut() .rust_2024_migration_desugared_pats_mut() - .insert(pat_info.top_info.hir_id); + .entry(pat_info.top_info.hir_id) + .or_default() |= pat.span.at_least_rust_2024(); BindingMode(ByRef::No, Mutability::Mut) } } @@ -2206,14 +2208,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } else { // Reset binding mode on old editions - if pat_info.binding_mode != ByRef::No { pat_info.binding_mode = ByRef::No; - - self.typeck_results + *self + .typeck_results .borrow_mut() .rust_2024_migration_desugared_pats_mut() - .insert(pat_info.top_info.hir_id); + .entry(pat_info.top_info.hir_id) + .or_default() |= pat.span.at_least_rust_2024(); } } @@ -2264,6 +2266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (err, err) } }; + self.check_pat(inner, inner_ty, pat_info); ref_ty } diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index c2555d2bb47dc..8164c7377529b 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -640,7 +640,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { #[instrument(skip(self), level = "debug")] fn visit_rust_2024_migration_desugared_pats(&mut self, hir_id: hir::HirId) { - if self + if let Some(is_hard_error) = self .fcx .typeck_results .borrow_mut() @@ -650,7 +650,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { debug!( "node is a pat whose match ergonomics are desugared by the Rust 2024 migration lint" ); - self.typeck_results.rust_2024_migration_desugared_pats_mut().insert(hir_id); + self.typeck_results + .rust_2024_migration_desugared_pats_mut() + .insert(hir_id, is_hard_error); } } diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 9b6d63c2ef480..06e63bd73411d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1650,7 +1650,7 @@ declare_lint! { /// ### Example /// /// ```rust,edition2021 - /// #![feature(ref_pat_eat_one_layer_2024)] + /// #![feature(min_match_ergonomics_2024)] /// #![warn(rust_2024_incompatible_pat)] /// /// if let Some(&a) = &Some(&0u8) { @@ -1671,7 +1671,7 @@ declare_lint! { pub RUST_2024_INCOMPATIBLE_PAT, Allow, "detects patterns whose meaning will change in Rust 2024", - @feature_gate = ref_pat_eat_one_layer_2024; + @feature_gate = min_match_ergonomics_2024; // FIXME uncomment below upon stabilization /*@future_incompatible = FutureIncompatibleInfo { reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024), diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index a92bdb2eae0de..c13d229ebdcba 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -79,9 +79,10 @@ pub struct TypeckResults<'tcx> { /// Stores the actual binding mode for all instances of [`BindingMode`]. pat_binding_modes: ItemLocalMap, - /// Top-level patterns whose match ergonomics need to be desugared - /// by the Rust 2021 -> 2024 migration lint. - rust_2024_migration_desugared_pats: ItemLocalSet, + /// Top-level patterns whose match ergonomics need to be desugared by the Rust 2021 -> 2024 + /// migration lint. The boolean indicates whether the emitted diagnostic should be a hard error + /// (if any of the incompatible pattern elements are in edition 2024). + rust_2024_migration_desugared_pats: ItemLocalMap, /// Stores the types which were implicitly dereferenced in pattern binding modes /// for later usage in THIR lowering. For example, @@ -437,15 +438,15 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_adjustments } } - pub fn rust_2024_migration_desugared_pats(&self) -> LocalSetInContext<'_> { - LocalSetInContext { + pub fn rust_2024_migration_desugared_pats(&self) -> LocalTableInContext<'_, bool> { + LocalTableInContext { hir_owner: self.hir_owner, data: &self.rust_2024_migration_desugared_pats, } } - pub fn rust_2024_migration_desugared_pats_mut(&mut self) -> LocalSetInContextMut<'_> { - LocalSetInContextMut { + pub fn rust_2024_migration_desugared_pats_mut(&mut self) -> LocalTableInContextMut<'_, bool> { + LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.rust_2024_migration_desugared_pats, } diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 411e9420914da..7f905d5b90b75 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -983,6 +983,8 @@ pub(crate) struct Rust2024IncompatiblePat { pub(crate) struct Rust2024IncompatiblePatSugg { pub(crate) suggestion: Vec<(Span, String)>, + /// Whether the incompatibility is a hard error because a relevant span is in edition 2024. + pub(crate) is_hard_error: bool, } impl Subdiagnostic for Rust2024IncompatiblePatSugg { diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index d78e1f5da09f0..90355d7fce691 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -48,18 +48,30 @@ pub(super) fn pat_from_hir<'a, 'tcx>( typeck_results, rust_2024_migration_suggestion: typeck_results .rust_2024_migration_desugared_pats() - .contains(pat.hir_id) - .then_some(Rust2024IncompatiblePatSugg { suggestion: Vec::new() }), + .get(pat.hir_id) + .map(|&is_hard_error| Rust2024IncompatiblePatSugg { + suggestion: Vec::new(), + is_hard_error, + }), }; let result = pcx.lower_pattern(pat); debug!("pat_from_hir({:?}) = {:?}", pat, result); if let Some(sugg) = pcx.rust_2024_migration_suggestion { - tcx.emit_node_span_lint( - lint::builtin::RUST_2024_INCOMPATIBLE_PAT, - pat.hir_id, - pat.span, - Rust2024IncompatiblePat { sugg }, - ); + if tcx.features().min_match_ergonomics_2024 && sugg.is_hard_error { + let mut err = tcx.dcx().struct_span_err( + pat.span, + "patterns are not allowed to reset the default binding mode in rust 2024", + ); + err.subdiagnostic(sugg); + err.emit(); + } else { + tcx.emit_node_span_lint( + lint::builtin::RUST_2024_INCOMPATIBLE_PAT, + pat.hir_id, + pat.span, + Rust2024IncompatiblePat { sugg }, + ); + } } result } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index 528d274c0ac2a..63c84ae5b9976 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -2,7 +2,7 @@ //@ run-rustfix //@ rustfix-only-machine-applicable //@ aux-build:migration_lint_macros.rs -#![feature(mut_ref, ref_pat_eat_one_layer_2024)] +#![feature(mut_ref, min_match_ergonomics_2024)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] @@ -114,14 +114,13 @@ fn main() { assert_type_eq(c, &&0u32); } - #[warn(rust_2024_incompatible_pat)] match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. - (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { - //~^ WARN: the semantics of this pattern will change in edition 2024 + &(Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { + //~^ ERROR: patterns are not allowed to reset the default binding mode assert_type_eq(x, 0u32); - assert_type_eq(y, &0u32); + assert_type_eq(y, 0u32); } _ => {} } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index 0c5be2c761d16..f2a83c1266bf2 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -2,7 +2,7 @@ //@ run-rustfix //@ rustfix-only-machine-applicable //@ aux-build:migration_lint_macros.rs -#![feature(mut_ref, ref_pat_eat_one_layer_2024)] +#![feature(mut_ref, min_match_ergonomics_2024)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] @@ -114,14 +114,13 @@ fn main() { assert_type_eq(c, &&0u32); } - #[warn(rust_2024_incompatible_pat)] match &(Some(0), Some(0)) { // The two patterns are the same syntactically, but because they're defined in different // editions they don't mean the same thing. (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { - //~^ WARN: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode assert_type_eq(x, 0u32); - assert_type_eq(y, &0u32); + assert_type_eq(y, 0u32); } _ => {} } diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index 29e9183acc3be..5e42e03d6685b 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -120,21 +120,13 @@ help: desugar the match ergonomics LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = | + + + +++ -warning: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:121:9 +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/migration_lint.rs:120:9 | LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/migration_lint.rs:117:12 - | -LL | #[warn(rust_2024_incompatible_pat)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: desugar the match ergonomics - | -LL | &(Some(mut x), migration_lint_macros::mixed_edition_pat!(ref y)) => { - | + +++ + | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&` -error: aborting due to 13 previous errors; 1 warning emitted +error: aborting due to 14 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs new file mode 100644 index 0000000000000..283666fdf4cab --- /dev/null +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs @@ -0,0 +1,49 @@ +//@ check-fail +//@ edition: 2024 +//@ compile-flags: -Zunstable-options +// gate-test-min_match_ergonomics_2024 +#![feature(min_match_ergonomics_2024)] +#![allow(incomplete_features)] +#![deny(rust_2024_incompatible_pat)] + +fn main() {} + +#[derive(Copy, Clone)] +struct T; + +struct Foo { + f: &'static (u8,), +} + +macro_rules! test_pat_on_type { + ($($tt:tt)*) => { + const _: () = { + // Define a new function to ensure all cases are tested independently. + fn foo($($tt)*) {} + }; + }; +} + +test_pat_on_type![(&x,): &(T,)]; //~ ERROR mismatched types +test_pat_on_type![(&x,): &(&T,)]; //~ ERROR patterns are not allowed to reset the default binding mode +test_pat_on_type![(&x,): &(&mut T,)]; //~ ERROR mismatched types +test_pat_on_type![(&mut x,): &(&T,)]; //~ ERROR mismatched types +test_pat_on_type![(&mut x,): &(&mut T,)]; //~ ERROR patterns are not allowed to reset the default binding mode +test_pat_on_type![(&x,): &&mut &(T,)]; //~ ERROR mismatched types +test_pat_on_type![Foo { f: (&x,) }: Foo]; //~ ERROR mismatched types +test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; //~ ERROR mismatched types +test_pat_on_type![Foo { f: &(x,) }: &Foo]; //~ ERROR patterns are not allowed to reset the default binding mode +test_pat_on_type![(mut x,): &(T,)]; //~ ERROR patterns are not allowed to reset the default binding mode +test_pat_on_type![(ref x,): &(T,)]; +test_pat_on_type![(ref mut x,): &mut (T,)]; + +fn get() -> X { + unimplemented!() +} + +// Make sure this works even when the underlying type is inferred. This test passes on rust stable. +fn infer() -> X { + match &get() { + (&x,) => x, //~ ERROR patterns are not allowed to reset the default binding mode + } +} diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr new file mode 100644 index 0000000000000..22247847def2d --- /dev/null +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr @@ -0,0 +1,144 @@ +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:27:20 + | +LL | test_pat_on_type![(&x,): &(T,)]; + | ^^ ----- expected due to this + | | + | expected `T`, found `&_` + | + = note: expected struct `T` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - test_pat_on_type![(&x,): &(T,)]; +LL + test_pat_on_type![(x,): &(T,)]; + | + +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:29:20 + | +LL | test_pat_on_type![(&x,): &(&mut T,)]; + | ^^ ---------- expected due to this + | | + | types differ in mutability + | + = note: expected mutable reference `&mut T` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - test_pat_on_type![(&x,): &(&mut T,)]; +LL + test_pat_on_type![(x,): &(&mut T,)]; + | + +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:30:20 + | +LL | test_pat_on_type![(&mut x,): &(&T,)]; + | ^^^^^^ ------ expected due to this + | | + | types differ in mutability + | + = note: expected reference `&T` + found mutable reference `&mut _` +note: to declare a mutable binding use: `mut x` + --> $DIR/min_match_ergonomics_fail.rs:30:20 + | +LL | test_pat_on_type![(&mut x,): &(&T,)]; + | ^^^^^^ +help: consider removing `&mut` from the pattern + | +LL - test_pat_on_type![(&mut x,): &(&T,)]; +LL + test_pat_on_type![(x,): &(&T,)]; + | + +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:32:20 + | +LL | test_pat_on_type![(&x,): &&mut &(T,)]; + | ^^ ----------- expected due to this + | | + | expected `T`, found `&_` + | + = note: expected struct `T` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - test_pat_on_type![(&x,): &&mut &(T,)]; +LL + test_pat_on_type![(x,): &&mut &(T,)]; + | + +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:33:29 + | +LL | test_pat_on_type![Foo { f: (&x,) }: Foo]; + | ^^ --- expected due to this + | | + | expected `u8`, found `&_` + | + = note: expected type `u8` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - test_pat_on_type![Foo { f: (&x,) }: Foo]; +LL + test_pat_on_type![Foo { f: (x,) }: Foo]; + | + +error[E0308]: mismatched types + --> $DIR/min_match_ergonomics_fail.rs:34:29 + | +LL | test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; + | ^^ -------- expected due to this + | | + | expected `u8`, found `&_` + | + = note: expected type `u8` + found reference `&_` +help: consider removing `&` from the pattern + | +LL - test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; +LL + test_pat_on_type![Foo { f: (x,) }: &mut Foo]; + | + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:28:19 + | +LL | test_pat_on_type![(&x,): &(&T,)]; + | -^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:31:19 + | +LL | test_pat_on_type![(&mut x,): &(&mut T,)]; + | -^^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:35:19 + | +LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; + | -^^^^^^^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:36:19 + | +LL | test_pat_on_type![(mut x,): &(T,)]; + | -^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:47:9 + | +LL | (&x,) => x, + | -^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: aborting due to 11 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs new file mode 100644 index 0000000000000..8dbbd7cfbb0c8 --- /dev/null +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs @@ -0,0 +1,19 @@ +//@ revisions: normal min_match_ergonomics +//@ check-pass +#![cfg_attr(min_match_ergonomics, feature(min_match_ergonomics_2024))] +#![allow(incomplete_features)] + +fn main() {} + +// Tests type equality in a way that avoids coercing `&&T` to `&T`. +trait Eq {} +impl Eq for T {} +fn assert_type_eq>(_: T, _: U) {} + +#[derive(Copy, Clone)] +struct T; + +fn test() { + let (x,) = &(&T,); + assert_type_eq(x, &&T); +} From 575033c50cf3f530bb054211e3dae968d373037f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Oct 2024 23:39:33 +0200 Subject: [PATCH 5/7] Also disallow `ref`/`ref mut` overriding the binding mode --- compiler/rustc_hir_typeck/src/pat.rs | 15 ++++++- .../migration_lint.fixed | 6 ++- .../migration_lint.rs | 2 + .../migration_lint.stderr | 42 +++++++++++++------ .../min_match_ergonomics_fail.rs | 4 +- .../min_match_ergonomics_fail.stderr | 18 +++++++- 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 8eb3118fb8ad8..9ac5367d5d993 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -691,7 +691,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { BindingMode(def_br, Mutability::Mut) } else { - // `mut` resets binding mode on edition <= 2021 + // `mut` resets the binding mode on edition <= 2021 *self .typeck_results .borrow_mut() @@ -702,7 +702,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } BindingMode(ByRef::No, mutbl) => BindingMode(def_br, mutbl), - BindingMode(ByRef::Yes(_), _) => user_bind_annot, + BindingMode(ByRef::Yes(_), _) => { + if matches!(def_br, ByRef::Yes(_)) { + // `ref`/`ref mut` overrides the binding mode on edition <= 2021 + *self + .typeck_results + .borrow_mut() + .rust_2024_migration_desugared_pats_mut() + .entry(pat_info.top_info.hir_id) + .or_default() |= pat.span.at_least_rust_2024(); + } + user_bind_annot + } }; if bm.0 == ByRef::Yes(Mutability::Mut) diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index 63c84ae5b9976..a0fc34826a2f0 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -30,10 +30,12 @@ fn main() { //~^ ERROR: the semantics of this pattern will change in edition 2024 assert_type_eq(x, 0u8); - let Foo(ref x) = &Foo(0); + let &Foo(ref x) = &Foo(0); + //~^ ERROR: the semantics of this pattern will change in edition 2024 assert_type_eq(x, &0u8); - let Foo(ref x) = &mut Foo(0); + let &mut Foo(ref x) = &mut Foo(0); + //~^ ERROR: the semantics of this pattern will change in edition 2024 assert_type_eq(x, &0u8); let &Foo(x) = &Foo(0); diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index f2a83c1266bf2..6fdea065dc0f2 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -31,9 +31,11 @@ fn main() { assert_type_eq(x, 0u8); let Foo(ref x) = &Foo(0); + //~^ ERROR: the semantics of this pattern will change in edition 2024 assert_type_eq(x, &0u8); let Foo(ref x) = &mut Foo(0); + //~^ ERROR: the semantics of this pattern will change in edition 2024 assert_type_eq(x, &0u8); let &Foo(x) = &Foo(0); diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index 5e42e03d6685b..f429b96010d70 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -21,7 +21,23 @@ LL | let Foo(mut x) = &mut Foo(0); | help: desugar the match ergonomics: `&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:51:9 + --> $DIR/migration_lint.rs:33:9 + | +LL | let Foo(ref x) = &Foo(0); + | -^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:37:9 + | +LL | let Foo(ref x) = &mut Foo(0); + | -^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&mut` + +error: the semantics of this pattern will change in edition 2024 + --> $DIR/migration_lint.rs:53:9 | LL | let Foo(&x) = &Foo(&0); | -^^^^^^ @@ -29,7 +45,7 @@ LL | let Foo(&x) = &Foo(&0); | help: desugar the match ergonomics: `&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:55:9 + --> $DIR/migration_lint.rs:57:9 | LL | let Foo(&mut x) = &Foo(&mut 0); | -^^^^^^^^^^ @@ -37,7 +53,7 @@ LL | let Foo(&mut x) = &Foo(&mut 0); | help: desugar the match ergonomics: `&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:59:9 + --> $DIR/migration_lint.rs:61:9 | LL | let Foo(&x) = &mut Foo(&0); | -^^^^^^ @@ -45,7 +61,7 @@ LL | let Foo(&x) = &mut Foo(&0); | help: desugar the match ergonomics: `&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:63:9 + --> $DIR/migration_lint.rs:65:9 | LL | let Foo(&mut x) = &mut Foo(&mut 0); | -^^^^^^^^^^ @@ -53,7 +69,7 @@ LL | let Foo(&mut x) = &mut Foo(&mut 0); | help: desugar the match ergonomics: `&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:71:12 + --> $DIR/migration_lint.rs:73:12 | LL | if let Some(&x) = &&&&&Some(&0u8) { | -^^^^^^^ @@ -61,7 +77,7 @@ LL | if let Some(&x) = &&&&&Some(&0u8) { | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:76:12 + --> $DIR/migration_lint.rs:78:12 | LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { | -^^^^^^^^^^^ @@ -69,7 +85,7 @@ LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { | help: desugar the match ergonomics: `&&&&&` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:81:12 + --> $DIR/migration_lint.rs:83:12 | LL | if let Some(&x) = &&&&&mut Some(&0u8) { | -^^^^^^^ @@ -77,7 +93,7 @@ LL | if let Some(&x) = &&&&&mut Some(&0u8) { | help: desugar the match ergonomics: `&&&&&mut` error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:86:12 + --> $DIR/migration_lint.rs:88:12 | LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +104,7 @@ LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some | ++++ ++++ +++++++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:97:9 + --> $DIR/migration_lint.rs:99:9 | LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +115,7 @@ LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; | + +++ +++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:102:9 + --> $DIR/migration_lint.rs:104:9 | LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -110,7 +126,7 @@ LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; | + +++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:108:12 + --> $DIR/migration_lint.rs:110:12 | LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,12 +137,12 @@ LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = | + + + +++ error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/migration_lint.rs:120:9 + --> $DIR/migration_lint.rs:122:9 | LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | help: desugar the match ergonomics: `&` -error: aborting due to 14 previous errors +error: aborting due to 16 previous errors diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs index 283666fdf4cab..c5d2199852ba1 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs @@ -34,8 +34,8 @@ test_pat_on_type![Foo { f: (&x,) }: Foo]; //~ ERROR mismatched types test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; //~ ERROR mismatched types test_pat_on_type![Foo { f: &(x,) }: &Foo]; //~ ERROR patterns are not allowed to reset the default binding mode test_pat_on_type![(mut x,): &(T,)]; //~ ERROR patterns are not allowed to reset the default binding mode -test_pat_on_type![(ref x,): &(T,)]; -test_pat_on_type![(ref mut x,): &mut (T,)]; +test_pat_on_type![(ref x,): &(T,)]; //~ ERROR patterns are not allowed to reset the default binding mode +test_pat_on_type![(ref mut x,): &mut (T,)]; //~ ERROR patterns are not allowed to reset the default binding mode fn get() -> X { unimplemented!() diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr index 22247847def2d..8f189e1cf0793 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr @@ -131,6 +131,22 @@ LL | test_pat_on_type![(mut x,): &(T,)]; | | | help: desugar the match ergonomics: `&` +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:37:19 + | +LL | test_pat_on_type![(ref x,): &(T,)]; + | -^^^^^^^ + | | + | help: desugar the match ergonomics: `&` + +error: patterns are not allowed to reset the default binding mode in rust 2024 + --> $DIR/min_match_ergonomics_fail.rs:38:19 + | +LL | test_pat_on_type![(ref mut x,): &mut (T,)]; + | -^^^^^^^^^^^ + | | + | help: desugar the match ergonomics: `&mut` + error: patterns are not allowed to reset the default binding mode in rust 2024 --> $DIR/min_match_ergonomics_fail.rs:47:9 | @@ -139,6 +155,6 @@ LL | (&x,) => x, | | | help: desugar the match ergonomics: `&` -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0308`. From 4aaada42d0b59c3294908f9996277c60d9e13917 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Oct 2024 23:47:21 +0200 Subject: [PATCH 6/7] Stabilize `min_match_ergonomics_2024` --- compiler/rustc_feature/src/unstable.rs | 3 - compiler/rustc_lint_defs/src/builtin.rs | 7 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 - .../migration_lint.fixed | 17 ++++- .../migration_lint.rs | 17 ++++- .../migration_lint.stderr | 70 +++++++++++++++---- .../min_match_ergonomics_fail.rs | 3 - .../min_match_ergonomics_fail.stderr | 28 ++++---- .../min_match_ergonomics_success.rs | 2 - 10 files changed, 104 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 5fff81d3e1cd7..fa3a7049f4a07 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -516,9 +516,6 @@ declare_features! ( (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), - /// A very restricted form of match ergonomics used over the 2024 edition transition to give - /// more time for T-lang to decide the final form of RFC3627. - (incomplete, min_match_ergonomics_2024, "CURRENT_RUSTC_VERSION", Some(123076)), /// A minimal, sound subset of specialization intended to be used by the /// standard library until the soundness issues with specialization /// are fixed. diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 06e63bd73411d..b73ceb91c400e 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1650,7 +1650,6 @@ declare_lint! { /// ### Example /// /// ```rust,edition2021 - /// #![feature(min_match_ergonomics_2024)] /// #![warn(rust_2024_incompatible_pat)] /// /// if let Some(&a) = &Some(&0u8) { @@ -1671,12 +1670,10 @@ declare_lint! { pub RUST_2024_INCOMPATIBLE_PAT, Allow, "detects patterns whose meaning will change in Rust 2024", - @feature_gate = min_match_ergonomics_2024; - // FIXME uncomment below upon stabilization - /*@future_incompatible = FutureIncompatibleInfo { + @future_incompatible = FutureIncompatibleInfo { reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024), reference: "123076", - };*/ + }; } declare_lint! { diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 90355d7fce691..bb02ee37733c9 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -57,7 +57,7 @@ pub(super) fn pat_from_hir<'a, 'tcx>( let result = pcx.lower_pattern(pat); debug!("pat_from_hir({:?}) = {:?}", pat, result); if let Some(sugg) = pcx.rust_2024_migration_suggestion { - if tcx.features().min_match_ergonomics_2024 && sugg.is_hard_error { + if sugg.is_hard_error { let mut err = tcx.dcx().struct_span_err( pat.span, "patterns are not allowed to reset the default binding mode in rust 2024", diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 81ae66ccf6807..402232a1720b7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1218,7 +1218,6 @@ symbols! { min_const_generics, min_const_unsafe_fn, min_exhaustive_patterns, - min_match_ergonomics_2024, min_specialization, min_type_alias_impl_trait, minnumf128, diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index a0fc34826a2f0..90c35b5a69723 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -2,7 +2,7 @@ //@ run-rustfix //@ rustfix-only-machine-applicable //@ aux-build:migration_lint_macros.rs -#![feature(mut_ref, min_match_ergonomics_2024)] +#![feature(mut_ref)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] @@ -24,18 +24,22 @@ fn main() { let &Foo(mut x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(mut x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &Foo(ref x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let &mut Foo(ref x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let &Foo(x) = &Foo(0); @@ -52,18 +56,22 @@ fn main() { let &Foo(&x) = &Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &Foo(&mut x) = &Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(&x) = &mut Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(&mut x) = &mut Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); if let Some(x) = &&&&&Some(&0u8) { @@ -72,21 +80,25 @@ fn main() { if let &&&&&Some(&x) = &&&&&Some(&0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &mut 0u8); } @@ -98,17 +110,20 @@ fn main() { let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, &0u32); assert_type_eq(b, 0u32); let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, 0u32); assert_type_eq(b, &&0u32); assert_type_eq(c, &&0u32); if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) { assert_type_eq(a, &0u32); diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index 6fdea065dc0f2..04d547f301867 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -2,7 +2,7 @@ //@ run-rustfix //@ rustfix-only-machine-applicable //@ aux-build:migration_lint_macros.rs -#![feature(mut_ref, min_match_ergonomics_2024)] +#![feature(mut_ref)] #![allow(incomplete_features, unused)] #![deny(rust_2024_incompatible_pat)] @@ -24,18 +24,22 @@ fn main() { let Foo(mut x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(mut x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(ref x) = &Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let Foo(ref x) = &mut Foo(0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let &Foo(x) = &Foo(0); @@ -52,18 +56,22 @@ fn main() { let Foo(&x) = &Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&mut x) = &Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&x) = &mut Foo(&0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&mut x) = &mut Foo(&mut 0); //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); if let Some(x) = &&&&&Some(&0u8) { @@ -72,21 +80,25 @@ fn main() { if let Some(&x) = &&&&&Some(&0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&mut x) = &&&&&Some(&mut 0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&x) = &&&&&mut Some(&0u8) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &mut 0u8); } @@ -98,17 +110,20 @@ fn main() { let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, &0u32); assert_type_eq(b, 0u32); let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, 0u32); assert_type_eq(b, &&0u32); assert_type_eq(c, &&0u32); if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~| WARN: this changes meaning in Rust 2024 &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) { assert_type_eq(a, &0u32); diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index f429b96010d70..4881748f71adf 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -6,6 +6,8 @@ LL | let Foo(mut x) = &Foo(0); | | | help: desugar the match ergonomics: `&` | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 note: the lint level is defined here --> $DIR/migration_lint.rs:7:9 | @@ -13,131 +15,169 @@ LL | #![deny(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:29:9 + --> $DIR/migration_lint.rs:30:9 | LL | let Foo(mut x) = &mut Foo(0); | -^^^^^^^^^ | | | help: desugar the match ergonomics: `&mut` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:33:9 + --> $DIR/migration_lint.rs:35:9 | LL | let Foo(ref x) = &Foo(0); | -^^^^^^^^^ | | | help: desugar the match ergonomics: `&` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:37:9 + --> $DIR/migration_lint.rs:40:9 | LL | let Foo(ref x) = &mut Foo(0); | -^^^^^^^^^ | | | help: desugar the match ergonomics: `&mut` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:53:9 + --> $DIR/migration_lint.rs:57:9 | LL | let Foo(&x) = &Foo(&0); | -^^^^^^ | | | help: desugar the match ergonomics: `&` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:57:9 + --> $DIR/migration_lint.rs:62:9 | LL | let Foo(&mut x) = &Foo(&mut 0); | -^^^^^^^^^^ | | | help: desugar the match ergonomics: `&` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:61:9 + --> $DIR/migration_lint.rs:67:9 | LL | let Foo(&x) = &mut Foo(&0); | -^^^^^^ | | | help: desugar the match ergonomics: `&mut` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:65:9 + --> $DIR/migration_lint.rs:72:9 | LL | let Foo(&mut x) = &mut Foo(&mut 0); | -^^^^^^^^^^ | | | help: desugar the match ergonomics: `&mut` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:73:12 + --> $DIR/migration_lint.rs:81:12 | LL | if let Some(&x) = &&&&&Some(&0u8) { | -^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:78:12 + --> $DIR/migration_lint.rs:87:12 | LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { | -^^^^^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:83:12 + --> $DIR/migration_lint.rs:93:12 | LL | if let Some(&x) = &&&&&mut Some(&0u8) { | -^^^^^^^ | | | help: desugar the match ergonomics: `&&&&&mut` + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:88:12 + --> $DIR/migration_lint.rs:99:12 | LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { | ^^^^^^^^^^^^^^^^^^^^^^^^ | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 help: desugar the match ergonomics | LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { | ++++ ++++ +++++++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:99:9 + --> $DIR/migration_lint.rs:111:9 | LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^ | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 help: desugar the match ergonomics | LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; | + +++ +++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:104:9 + --> $DIR/migration_lint.rs:117:9 | LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 help: desugar the match ergonomics | LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; | + +++ error: the semantics of this pattern will change in edition 2024 - --> $DIR/migration_lint.rs:110:12 + --> $DIR/migration_lint.rs:124:12 | LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | + = warning: this changes meaning in Rust 2024 + = note: for more information, see 123076 help: desugar the match ergonomics | LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = | + + + +++ error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/migration_lint.rs:122:9 + --> $DIR/migration_lint.rs:137:9 | LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs index c5d2199852ba1..a822c90ab6e5a 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.rs @@ -1,9 +1,6 @@ //@ check-fail //@ edition: 2024 //@ compile-flags: -Zunstable-options -// gate-test-min_match_ergonomics_2024 -#![feature(min_match_ergonomics_2024)] -#![allow(incomplete_features)] #![deny(rust_2024_incompatible_pat)] fn main() {} diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr index 8f189e1cf0793..ca34ad8d0ece3 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:27:20 + --> $DIR/min_match_ergonomics_fail.rs:24:20 | LL | test_pat_on_type![(&x,): &(T,)]; | ^^ ----- expected due to this @@ -15,7 +15,7 @@ LL + test_pat_on_type![(x,): &(T,)]; | error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:29:20 + --> $DIR/min_match_ergonomics_fail.rs:26:20 | LL | test_pat_on_type![(&x,): &(&mut T,)]; | ^^ ---------- expected due to this @@ -31,7 +31,7 @@ LL + test_pat_on_type![(x,): &(&mut T,)]; | error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:30:20 + --> $DIR/min_match_ergonomics_fail.rs:27:20 | LL | test_pat_on_type![(&mut x,): &(&T,)]; | ^^^^^^ ------ expected due to this @@ -41,7 +41,7 @@ LL | test_pat_on_type![(&mut x,): &(&T,)]; = note: expected reference `&T` found mutable reference `&mut _` note: to declare a mutable binding use: `mut x` - --> $DIR/min_match_ergonomics_fail.rs:30:20 + --> $DIR/min_match_ergonomics_fail.rs:27:20 | LL | test_pat_on_type![(&mut x,): &(&T,)]; | ^^^^^^ @@ -52,7 +52,7 @@ LL + test_pat_on_type![(x,): &(&T,)]; | error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:32:20 + --> $DIR/min_match_ergonomics_fail.rs:29:20 | LL | test_pat_on_type![(&x,): &&mut &(T,)]; | ^^ ----------- expected due to this @@ -68,7 +68,7 @@ LL + test_pat_on_type![(x,): &&mut &(T,)]; | error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:33:29 + --> $DIR/min_match_ergonomics_fail.rs:30:29 | LL | test_pat_on_type![Foo { f: (&x,) }: Foo]; | ^^ --- expected due to this @@ -84,7 +84,7 @@ LL + test_pat_on_type![Foo { f: (x,) }: Foo]; | error[E0308]: mismatched types - --> $DIR/min_match_ergonomics_fail.rs:34:29 + --> $DIR/min_match_ergonomics_fail.rs:31:29 | LL | test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; | ^^ -------- expected due to this @@ -100,7 +100,7 @@ LL + test_pat_on_type![Foo { f: (x,) }: &mut Foo]; | error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:28:19 + --> $DIR/min_match_ergonomics_fail.rs:25:19 | LL | test_pat_on_type![(&x,): &(&T,)]; | -^^^^ @@ -108,7 +108,7 @@ LL | test_pat_on_type![(&x,): &(&T,)]; | help: desugar the match ergonomics: `&` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:31:19 + --> $DIR/min_match_ergonomics_fail.rs:28:19 | LL | test_pat_on_type![(&mut x,): &(&mut T,)]; | -^^^^^^^^ @@ -116,7 +116,7 @@ LL | test_pat_on_type![(&mut x,): &(&mut T,)]; | help: desugar the match ergonomics: `&` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:35:19 + --> $DIR/min_match_ergonomics_fail.rs:32:19 | LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; | -^^^^^^^^^^^^^^^ @@ -124,7 +124,7 @@ LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; | help: desugar the match ergonomics: `&` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:36:19 + --> $DIR/min_match_ergonomics_fail.rs:33:19 | LL | test_pat_on_type![(mut x,): &(T,)]; | -^^^^^^^ @@ -132,7 +132,7 @@ LL | test_pat_on_type![(mut x,): &(T,)]; | help: desugar the match ergonomics: `&` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:37:19 + --> $DIR/min_match_ergonomics_fail.rs:34:19 | LL | test_pat_on_type![(ref x,): &(T,)]; | -^^^^^^^ @@ -140,7 +140,7 @@ LL | test_pat_on_type![(ref x,): &(T,)]; | help: desugar the match ergonomics: `&` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:38:19 + --> $DIR/min_match_ergonomics_fail.rs:35:19 | LL | test_pat_on_type![(ref mut x,): &mut (T,)]; | -^^^^^^^^^^^ @@ -148,7 +148,7 @@ LL | test_pat_on_type![(ref mut x,): &mut (T,)]; | help: desugar the match ergonomics: `&mut` error: patterns are not allowed to reset the default binding mode in rust 2024 - --> $DIR/min_match_ergonomics_fail.rs:47:9 + --> $DIR/min_match_ergonomics_fail.rs:44:9 | LL | (&x,) => x, | -^^^^ diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs index 8dbbd7cfbb0c8..0fb448afca9c7 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_success.rs @@ -1,6 +1,4 @@ -//@ revisions: normal min_match_ergonomics //@ check-pass -#![cfg_attr(min_match_ergonomics, feature(min_match_ergonomics_2024))] #![allow(incomplete_features)] fn main() {} From 2ef0a8fdfd5142e8a524f4dc9fff8c65d0bd7cc2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 8 Oct 2024 00:14:35 +0200 Subject: [PATCH 7/7] Change error message --- compiler/rustc_mir_build/messages.ftl | 2 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 7 ++-- .../migration_lint.fixed | 30 ++++++++--------- .../migration_lint.rs | 30 ++++++++--------- .../migration_lint.stderr | 32 +++++++++---------- .../min_match_ergonomics_fail.stderr | 14 ++++---- 6 files changed, 57 insertions(+), 58 deletions(-) diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index 1c4e9fd11cbd6..55149570dbc4d 100644 --- a/compiler/rustc_mir_build/messages.ftl +++ b/compiler/rustc_mir_build/messages.ftl @@ -265,7 +265,7 @@ mir_build_pointer_pattern = function pointers and raw pointers not derived from mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future -mir_build_rust_2024_incompatible_pat = the semantics of this pattern will change in edition 2024 +mir_build_rust_2024_incompatible_pat = patterns are not allowed to reset the default binding mode in edition 2024 mir_build_rustc_box_attribute_error = `#[rustc_box]` attribute used incorrectly .attributes = no other attributes may be applied diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index bb02ee37733c9..16b7cac4e4d5d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -25,6 +25,7 @@ use tracing::{debug, instrument}; pub(crate) use self::check_match::check_match; use crate::errors::*; +use crate::fluent_generated as fluent; use crate::thir::util::UserAnnotatedTyHelpers; struct PatCtxt<'a, 'tcx> { @@ -58,10 +59,8 @@ pub(super) fn pat_from_hir<'a, 'tcx>( debug!("pat_from_hir({:?}) = {:?}", pat, result); if let Some(sugg) = pcx.rust_2024_migration_suggestion { if sugg.is_hard_error { - let mut err = tcx.dcx().struct_span_err( - pat.span, - "patterns are not allowed to reset the default binding mode in rust 2024", - ); + let mut err = + tcx.dcx().struct_span_err(pat.span, fluent::mir_build_rust_2024_incompatible_pat); err.subdiagnostic(sugg); err.emit(); } else { diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed index 90c35b5a69723..086671e69cba1 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.fixed @@ -23,22 +23,22 @@ fn main() { assert_type_eq(x, &mut 0u8); let &Foo(mut x) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(mut x) = &mut Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &Foo(ref x) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let &mut Foo(ref x) = &mut Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); @@ -55,22 +55,22 @@ fn main() { assert_type_eq(x, &0u8); let &Foo(&x) = &Foo(&0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &Foo(&mut x) = &Foo(&mut 0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(&x) = &mut Foo(&0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let &mut Foo(&mut x) = &mut Foo(&mut 0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); @@ -79,25 +79,25 @@ fn main() { } if let &&&&&Some(&x) = &&&&&Some(&0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &mut 0u8); } @@ -109,20 +109,20 @@ fn main() { } let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, &0u32); assert_type_eq(b, 0u32); let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, 0u32); assert_type_eq(b, &&0u32); assert_type_eq(c, &&0u32); if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) { diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs index 04d547f301867..acceafdb7ec06 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.rs @@ -23,22 +23,22 @@ fn main() { assert_type_eq(x, &mut 0u8); let Foo(mut x) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(mut x) = &mut Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(ref x) = &Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); let Foo(ref x) = &mut Foo(0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &0u8); @@ -55,22 +55,22 @@ fn main() { assert_type_eq(x, &0u8); let Foo(&x) = &Foo(&0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&mut x) = &Foo(&mut 0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&x) = &mut Foo(&0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); let Foo(&mut x) = &mut Foo(&mut 0); - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); @@ -79,25 +79,25 @@ fn main() { } if let Some(&x) = &&&&&Some(&0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&mut x) = &&&&&Some(&mut 0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&x) = &&&&&mut Some(&0u8) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, 0u8); } if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(x, &mut 0u8); } @@ -109,20 +109,20 @@ fn main() { } let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, &0u32); assert_type_eq(b, 0u32); let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 assert_type_eq(a, 0u32); assert_type_eq(b, &&0u32); assert_type_eq(c, &&0u32); if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = - //~^ ERROR: the semantics of this pattern will change in edition 2024 + //~^ ERROR: patterns are not allowed to reset the default binding mode //~| WARN: this changes meaning in Rust 2024 &(Struct { a: &Some(&0), b: &Some(&0), c: &Some(&0) }) { diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index 4881748f71adf..1c9a469e6ee0d 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -1,4 +1,4 @@ -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:25:9 | LL | let Foo(mut x) = &Foo(0); @@ -14,7 +14,7 @@ note: the lint level is defined here LL | #![deny(rust_2024_incompatible_pat)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:30:9 | LL | let Foo(mut x) = &mut Foo(0); @@ -25,7 +25,7 @@ LL | let Foo(mut x) = &mut Foo(0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:35:9 | LL | let Foo(ref x) = &Foo(0); @@ -36,7 +36,7 @@ LL | let Foo(ref x) = &Foo(0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:40:9 | LL | let Foo(ref x) = &mut Foo(0); @@ -47,7 +47,7 @@ LL | let Foo(ref x) = &mut Foo(0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:57:9 | LL | let Foo(&x) = &Foo(&0); @@ -58,7 +58,7 @@ LL | let Foo(&x) = &Foo(&0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:62:9 | LL | let Foo(&mut x) = &Foo(&mut 0); @@ -69,7 +69,7 @@ LL | let Foo(&mut x) = &Foo(&mut 0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:67:9 | LL | let Foo(&x) = &mut Foo(&0); @@ -80,7 +80,7 @@ LL | let Foo(&x) = &mut Foo(&0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:72:9 | LL | let Foo(&mut x) = &mut Foo(&mut 0); @@ -91,7 +91,7 @@ LL | let Foo(&mut x) = &mut Foo(&mut 0); = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:81:12 | LL | if let Some(&x) = &&&&&Some(&0u8) { @@ -102,7 +102,7 @@ LL | if let Some(&x) = &&&&&Some(&0u8) { = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:87:12 | LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { @@ -113,7 +113,7 @@ LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:93:12 | LL | if let Some(&x) = &&&&&mut Some(&0u8) { @@ -124,7 +124,7 @@ LL | if let Some(&x) = &&&&&mut Some(&0u8) { = warning: this changes meaning in Rust 2024 = note: for more information, see 123076 -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:99:12 | LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { @@ -137,7 +137,7 @@ help: desugar the match ergonomics LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { | ++++ ++++ +++++++ -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:111:9 | LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; @@ -150,7 +150,7 @@ help: desugar the match ergonomics LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; | + +++ +++ -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:117:9 | LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; @@ -163,7 +163,7 @@ help: desugar the match ergonomics LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; | + +++ -error: the semantics of this pattern will change in edition 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:124:12 | LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = @@ -176,7 +176,7 @@ help: desugar the match ergonomics LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = | + + + +++ -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/migration_lint.rs:137:9 | LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr index ca34ad8d0ece3..33e4f0021b7ba 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr @@ -99,7 +99,7 @@ LL - test_pat_on_type![Foo { f: (&x,) }: &mut Foo]; LL + test_pat_on_type![Foo { f: (x,) }: &mut Foo]; | -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:25:19 | LL | test_pat_on_type![(&x,): &(&T,)]; @@ -107,7 +107,7 @@ LL | test_pat_on_type![(&x,): &(&T,)]; | | | help: desugar the match ergonomics: `&` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:28:19 | LL | test_pat_on_type![(&mut x,): &(&mut T,)]; @@ -115,7 +115,7 @@ LL | test_pat_on_type![(&mut x,): &(&mut T,)]; | | | help: desugar the match ergonomics: `&` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:32:19 | LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; @@ -123,7 +123,7 @@ LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; | | | help: desugar the match ergonomics: `&` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:33:19 | LL | test_pat_on_type![(mut x,): &(T,)]; @@ -131,7 +131,7 @@ LL | test_pat_on_type![(mut x,): &(T,)]; | | | help: desugar the match ergonomics: `&` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:34:19 | LL | test_pat_on_type![(ref x,): &(T,)]; @@ -139,7 +139,7 @@ LL | test_pat_on_type![(ref x,): &(T,)]; | | | help: desugar the match ergonomics: `&` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:35:19 | LL | test_pat_on_type![(ref mut x,): &mut (T,)]; @@ -147,7 +147,7 @@ LL | test_pat_on_type![(ref mut x,): &mut (T,)]; | | | help: desugar the match ergonomics: `&mut` -error: patterns are not allowed to reset the default binding mode in rust 2024 +error: patterns are not allowed to reset the default binding mode in edition 2024 --> $DIR/min_match_ergonomics_fail.rs:44:9 | LL | (&x,) => x,