]> git.lizzy.rs Git - rust.git/commitdiff
typeck/pat.rs: simplify `peel_off_references`.
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 23 Aug 2019 13:55:35 +0000 (15:55 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 17:14:59 +0000 (19:14 +0200)
src/librustc_typeck/check/pat.rs

index 625c57356af38e677fa4405063e5cd548e825bd0..ce033b85fce050bc53b97639837cf9b8fe88eefa 100644 (file)
@@ -553,22 +553,16 @@ fn peel_off_references(
             pat_adjustments.push(expected);
 
             expected = inner_ty;
-            def_bm = match def_bm {
+            def_bm = ty::BindByReference(match def_bm {
                 // If default binding mode is by value, make it `ref` or `ref mut`
                 // (depending on whether we observe `&` or `&mut`).
-                ty::BindByValue(_) =>
-                    ty::BindByReference(inner_mutability),
-
-                // Once a `ref`, always a `ref`. This is because a `& &mut` can't mutate
-                // the underlying value.
-                ty::BindByReference(hir::Mutability::MutImmutable) =>
-                    ty::BindByReference(hir::Mutability::MutImmutable),
-
-                // When `ref mut`, stay a `ref mut` (on `&mut`) or downgrade to `ref`
-                // (on `&`).
-                ty::BindByReference(hir::Mutability::MutMutable) =>
-                    ty::BindByReference(inner_mutability),
-            };
+                ty::BindByValue(_) |
+                // When `ref mut`, stay a `ref mut` (on `&mut`) or downgrade to `ref` (on `&`).
+                ty::BindByReference(hir::Mutability::MutMutable) => inner_mutability,
+                // Once a `ref`, always a `ref`.
+                // This is because a `& &mut` cannot mutate the underlying value.
+                ty::BindByReference(m @ hir::Mutability::MutImmutable) => m,
+            });
         }
 
         if pat_adjustments.len() > 0 {