diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index c8db4b97bae0d..5e0f37ed792ab 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -2217,7 +2217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("check_pat_ref: expected={:?}", expected);
match *expected.kind() {
ty::Ref(_, r_ty, r_mutbl)
- if (new_match_ergonomics && r_mutbl >= pat_mutbl)
+ if (no_ref_mut_behind_and && r_mutbl >= pat_mutbl)
|| r_mutbl == pat_mutbl =>
{
if no_ref_mut_behind_and && r_mutbl == Mutability::Not {
diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs
index d28567f2859a3..afea249ffef0b 100644
--- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs
+++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs
@@ -1,37 +1,15 @@
+//@ run-pass
//@ edition: 2021
+//@ revisions: classic structural both
#![allow(incomplete_features)]
-#![feature(ref_pat_eat_one_layer_2024)]
+#![cfg_attr(any(classic, both), feature(ref_pat_eat_one_layer_2024))]
+#![cfg_attr(any(structural, both), feature(ref_pat_eat_one_layer_2024_structural))]
+
pub fn main() {
- if let Some(Some(&x)) = &Some(&Some(0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
- }
- if let Some(Some(&x)) = &Some(Some(&0)) {
+ if let &Some(Some(x)) = &Some(&mut Some(0)) {
let _: &u32 = x;
- //~^ ERROR: mismatched types
- }
- if let Some(Some(&&x)) = &Some(Some(&0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
- }
- if let Some(&Some(x)) = &Some(Some(0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
- }
- if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
- }
- if let Some(Some(&x)) = &Some(&Some(0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
- }
- if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
- //~^ ERROR: mismatched types
- let _: u32 = x;
}
- if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
- //~^ ERROR: mismatched types
+ if let Some(&x) = Some(&mut 0) {
let _: u32 = x;
}
}
diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs
new file mode 100644
index 0000000000000..d28567f2859a3
--- /dev/null
+++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.rs
@@ -0,0 +1,37 @@
+//@ edition: 2021
+#![allow(incomplete_features)]
+#![feature(ref_pat_eat_one_layer_2024)]
+pub fn main() {
+ if let Some(Some(&x)) = &Some(&Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(Some(&x)) = &Some(Some(&0)) {
+ let _: &u32 = x;
+ //~^ ERROR: mismatched types
+ }
+ if let Some(Some(&&x)) = &Some(Some(&0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(&Some(x)) = &Some(Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(Some(&x)) = &Some(&Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(&mut Some(&x)) = &Some(&mut Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+ if let Some(&Some(&mut x)) = &mut Some(&Some(0)) {
+ //~^ ERROR: mismatched types
+ let _: u32 = x;
+ }
+}
diff --git a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr
similarity index 88%
rename from tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr
rename to tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr
index 28706f89c066b..1a921234ea069 100644
--- a/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.stderr
+++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021_fail.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/ref_pat_eat_one_layer_2021.rs:5:22
+ --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:5:22
|
LL | if let Some(Some(&x)) = &Some(&Some(0)) {
| ^^ --------------- this expression has type `&Option<&Option<{integer}>>`
@@ -14,7 +14,7 @@ LL | if let Some(Some(x)) = &Some(&Some(0)) {
| ~
error[E0308]: mismatched types
- --> $DIR/ref_pat_eat_one_layer_2021.rs:10:23
+ --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:10:23
|
LL | let _: &u32 = x;
| ---- ^ expected `&u32`, found integer
@@ -27,7 +27,7 @@ LL | let _: &u32 = &x;
| +
error[E0308]: mismatched types
- --> $DIR/ref_pat_eat_one_layer_2021.rs:13:23
+ --> $DIR/ref_pat_eat_one_layer_2021_fail.rs:13:23
|
LL | if let Some(Some(&&x)) = &Some(Some(&0)) {
| ^^ --------------- this expression has type `&Option