about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-08-20 23:59:46 +0100
committervarkor <github@varkor.com>2018-08-20 23:59:46 +0100
commitc421af995b567322d3f3fdeb1bccec02645cf25c (patch)
tree571a220c88a2b5a1d96d313c1ee02d0541ba2883
parent6e8a625674b6624fec6f7d40f10df27ca0c316bf (diff)
downloadrust-c421af995b567322d3f3fdeb1bccec02645cf25c.tar.gz
rust-c421af995b567322d3f3fdeb1bccec02645cf25c.zip
Add assertion to constructor_intersects_pattern
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 8c6f1d6759f..85e68a12a97 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -1517,7 +1517,14 @@ fn constructor_intersects_pattern<'p, 'a: 'p, 'tcx: 'a>(
 ) -> Option<Vec<&'p Pattern<'tcx>>> {
     if should_treat_range_exhaustively(tcx, ctor) {
         match (IntRange::from_ctor(tcx, ctor), IntRange::from_pat(tcx, pat)) {
-            (Some(ctor), Some(pat)) => ctor.intersection(&pat).map(|_| vec![]),
+            (Some(ctor), Some(pat)) => {
+                ctor.intersection(&pat).map(|_| {
+                    let (pat_lo, pat_hi) = pat.range.into_inner();
+                    let (ctor_lo, ctor_hi) = ctor.range.into_inner();
+                    assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
+                    Some(vec![])
+                })
+            }
             _ => None,
         }
     } else {
@@ -1656,21 +1663,18 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
                     }
                 }
                 _ => {
-                    // If the constructor is a single value, we add a row to the specialised matrix
-                    // if the pattern is equal to the constructor. If the constructor is a range of
-                    // values, we add a row to the specialised matrix if the pattern is contained
-                    // within the constructor. These two cases (for a single value pattern) can be
-                    // treated as intersection.
+                    // If the constructor is a:
+                    //      Single value: add a row if the constructor equals the pattern.
+                    //      Range: add a row if the constructor contains the pattern.
                     constructor_intersects_pattern(cx.tcx, constructor, pat)
                 }
             }
         }
 
         PatternKind::Range { .. } => {
-            // If the constructor is a single value, we add a row to the specialised matrix if the
-            // pattern contains the constructor. If the constructor is a range of values, we add a
-            // row to the specialised matrix if there exists any value that lies both within the
-            // pattern and the constructor. These two cases reduce to intersection.
+            // If the constructor is a:
+            //      Single value: add a row if the pattern contains the constructor.
+            //      Range: add a row if the constructor intersects the pattern.
             constructor_intersects_pattern(cx.tcx, constructor, pat)
         }