about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_ast/src/ast.rs4
-rw-r--r--compiler/rustc_hir_typeck/src/pat.rs8
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index fc7f64c7392..334ce5e060b 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -734,8 +734,8 @@ impl BindingAnnotation {
     }
 
     pub fn cap_ref_mutability(mut self, mutbl: Mutability) -> Self {
-        if let ByRef::Yes(old_mutbl) = self.0 {
-            self.0 = ByRef::Yes(cmp::min(old_mutbl, mutbl));
+        if let ByRef::Yes(old_mutbl) = &mut self.0 {
+            *old_mutbl = cmp::min(*old_mutbl, mutbl);
         }
         self
     }
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index 801c735ade3..28681365af5 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -447,10 +447,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 // This is because a `& &mut` cannot mutate the underlying value.
                 ByRef::Yes(Mutability::Not) => Mutability::Not,
             });
+        }
 
-            if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
-                max_ref_mutability = cmp::min(max_ref_mutability, inner_mutability);
-                def_bm = def_bm.cap_ref_mutability(max_ref_mutability);
+        if pat.span.at_least_rust_2024() && self.tcx.features().ref_pat_eat_one_layer_2024 {
+            def_bm = def_bm.cap_ref_mutability(max_ref_mutability);
+            if def_bm.0 == ByRef::Yes(Mutability::Not) {
+                max_ref_mutability = Mutability::Not;
             }
         }