about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJules Bertholet <julesbertholet@quoi.xyz>2024-07-05 11:16:48 -0400
committerJules Bertholet <julesbertholet@quoi.xyz>2024-07-05 11:17:13 -0400
commit5a35fc446e173d7a592bb859ffda9d97e996df5b (patch)
tree332c5cd69801f4584057c4afbaa827f52323b333
parent5fd5b650935c27754dcf8cef06df37c3b91818eb (diff)
downloadrust-5a35fc446e173d7a592bb859ffda9d97e996df5b.tar.gz
rust-5a35fc446e173d7a592bb859ffda9d97e996df5b.zip
Match ergonomics 2024: `&` matches `&mut` on old editions
-rw-r--r--compiler/rustc_hir_typeck/src/pat.rs2
-rw-r--r--tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs15
2 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index c8db4b97bae..5e0f37ed792 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
new file mode 100644
index 00000000000..afea249ffef
--- /dev/null
+++ b/tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2021.rs
@@ -0,0 +1,15 @@
+//@ run-pass
+//@ edition: 2021
+//@ revisions: classic structural both
+#![allow(incomplete_features)]
+#![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(&mut Some(0)) {
+        let _: &u32 = x;
+    }
+    if let Some(&x) = Some(&mut 0) {
+        let _: u32 = x;
+    }
+}