]> git.lizzy.rs Git - rust.git/commitdiff
Move logic from push_wild_constructor to apply_constructor
authorvarkor <github@varkor.com>
Sun, 12 Aug 2018 19:39:53 +0000 (20:39 +0100)
committervarkor <github@varkor.com>
Thu, 16 Aug 2018 19:09:05 +0000 (20:09 +0100)
src/librustc_mir/hair/pattern/_match.rs

index 065fbeda15360bf489b3f211d20a848667d59af2..26df06663401580d029486d793f8c1be5e300210 100644 (file)
@@ -351,38 +351,15 @@ fn push_wild_constructor<'a>(
         ty: Ty<'tcx>)
         -> Self
     {
-        // If we've been trying to exhaustively match over the domain of values for a type,
-        // then we can construct witnesses directly corresponding to the missing ranges of values,
-        // giving far more precise diagnostics.
-        // `ConstantValue` and `ConstantRange` only occur in practice when doing exhaustive value
-        // matching (exhaustive_integer_patterns).
-        match ctor {
-            ConstantValue(value) => {
-                Witness(vec![Pattern {
-                    ty,
-                    span: DUMMY_SP,
-                    kind: box PatternKind::Constant { value },
-                }])
-            }
-            ConstantRange(lo, hi, end) => {
-                Witness(vec![Pattern {
-                    ty,
-                    span: DUMMY_SP,
-                    kind: box PatternKind::Range { lo, hi, end: *end },
-                }])
+        let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
+        self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
+            Pattern {
+                ty,
+                span: DUMMY_SP,
+                kind: box PatternKind::Wild,
             }
-            _ => {
-                let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
-                self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
-                    Pattern {
-                        ty,
-                        span: DUMMY_SP,
-                        kind: box PatternKind::Wild,
-                    }
-                }));
-                self.apply_constructor(cx, ctor, ty)
-            }
-        }
+        }));
+        self.apply_constructor(cx, ctor, ty)
     }
 
 
@@ -409,7 +386,7 @@ fn apply_constructor<'a>(
         let arity = constructor_arity(cx, ctor, ty);
         let pat = {
             let len = self.0.len() as u64;
-            let mut pats = self.0.drain((len-arity) as usize..).rev();
+            let mut pats = self.0.drain((len - arity) as usize..).rev();
 
             match ty.sty {
                 ty::TyAdt(..) |
@@ -452,6 +429,7 @@ fn apply_constructor<'a>(
                 _ => {
                     match *ctor {
                         ConstantValue(value) => PatternKind::Constant { value },
+                        ConstantRange(lo, hi, end) => PatternKind::Range { lo, hi, end },
                         _ => PatternKind::Wild,
                     }
                 }