@@ -24,6 +24,7 @@ use pattern::{FieldPattern, Pattern, PatternKind};
2424use pattern:: { PatternFoldable , PatternFolder } ;
2525
2626use rustc:: hir:: def_id:: DefId ;
27+ use rustc:: hir:: RangeEnd ;
2728use rustc:: ty:: { self , AdtKind , Ty , TyCtxt , TypeFoldable } ;
2829
2930use rustc:: mir:: Field ;
@@ -206,8 +207,8 @@ pub enum Constructor {
206207 Variant ( DefId ) ,
207208 /// Literal values.
208209 ConstantValue ( ConstVal ) ,
209- /// Ranges of literal values (2..5 ).
210- ConstantRange ( ConstVal , ConstVal ) ,
210+ /// Ranges of literal values (` 2...5` and `2..5` ).
211+ ConstantRange ( ConstVal , ConstVal , RangeEnd ) ,
211212 /// Array patterns of length n.
212213 Slice ( usize ) ,
213214}
@@ -686,8 +687,8 @@ fn pat_constructors(_cx: &mut MatchCheckCtxt,
686687 Some ( vec ! [ Variant ( adt_def. variants[ variant_index] . did) ] ) ,
687688 PatternKind :: Constant { ref value } =>
688689 Some ( vec ! [ ConstantValue ( value. clone( ) ) ] ) ,
689- PatternKind :: Range { ref lo, ref hi } =>
690- Some ( vec ! [ ConstantRange ( lo. clone( ) , hi. clone( ) ) ] ) ,
690+ PatternKind :: Range { ref lo, ref hi, ref end } =>
691+ Some ( vec ! [ ConstantRange ( lo. clone( ) , hi. clone( ) , end . clone ( ) ) ] ) ,
691692 PatternKind :: Array { .. } => match pcx. ty . sty {
692693 ty:: TyArray ( _, length) => Some ( vec ! [ Slice ( length) ] ) ,
693694 _ => span_bug ! ( pat. span, "bad ty {:?} for array pattern" , pcx. ty)
@@ -791,17 +792,33 @@ fn slice_pat_covered_by_constructor(_tcx: TyCtxt, _span: Span,
791792
792793fn range_covered_by_constructor ( tcx : TyCtxt , span : Span ,
793794 ctor : & Constructor ,
794- from : & ConstVal , to : & ConstVal )
795+ from : & ConstVal , to : & ConstVal ,
796+ end : RangeEnd )
795797 -> Result < bool , ErrorReported > {
796- let ( c_from, c_to) = match * ctor {
797- ConstantValue ( ref value) => ( value, value) ,
798- ConstantRange ( ref from, ref to) => ( from, to) ,
799- Single => return Ok ( true ) ,
800- _ => bug ! ( )
801- } ;
802- let cmp_from = compare_const_vals ( tcx, span, c_from, from) ?;
803- let cmp_to = compare_const_vals ( tcx, span, c_to, to) ?;
804- Ok ( cmp_from != Ordering :: Less && cmp_to != Ordering :: Greater )
798+ let cmp_from = |c_from| Ok ( compare_const_vals ( tcx, span, c_from, from) ? != Ordering :: Less ) ;
799+ let cmp_to = |c_to| compare_const_vals ( tcx, span, c_to, to) ;
800+ match * ctor {
801+ ConstantValue ( ref value) => {
802+ let to = cmp_to ( value) ?;
803+ let end = ( to != Ordering :: Greater ) ||
804+ ( end == RangeEnd :: Excluded && to == Ordering :: Equal ) ;
805+ Ok ( cmp_from ( value) ? && end)
806+ } ,
807+ ConstantRange ( ref from, ref to, RangeEnd :: Included ) => {
808+ let to = cmp_to ( to) ?;
809+ let end = ( to != Ordering :: Greater ) ||
810+ ( end == RangeEnd :: Excluded && to == Ordering :: Equal ) ;
811+ Ok ( cmp_from ( from) ? && end)
812+ } ,
813+ ConstantRange ( ref from, ref to, RangeEnd :: Excluded ) => {
814+ let to = cmp_to ( to) ?;
815+ let end = ( to == Ordering :: Less ) ||
816+ ( end == RangeEnd :: Excluded && to == Ordering :: Equal ) ;
817+ Ok ( cmp_from ( from) ? && end)
818+ }
819+ Single => Ok ( true ) ,
820+ _ => bug ! ( ) ,
821+ }
805822}
806823
807824fn patterns_for_variant < ' p , ' a : ' p , ' tcx : ' a > (
@@ -872,7 +889,7 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
872889 } ,
873890 _ => {
874891 match range_covered_by_constructor (
875- cx. tcx , pat. span , constructor, value, value
892+ cx. tcx , pat. span , constructor, value, value, RangeEnd :: Included
876893 ) {
877894 Ok ( true ) => Some ( vec ! [ ] ) ,
878895 Ok ( false ) => None ,
@@ -882,9 +899,9 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
882899 }
883900 }
884901
885- PatternKind :: Range { ref lo, ref hi } => {
902+ PatternKind :: Range { ref lo, ref hi, ref end } => {
886903 match range_covered_by_constructor (
887- cx. tcx , pat. span , constructor, lo, hi
904+ cx. tcx , pat. span , constructor, lo, hi, end . clone ( )
888905 ) {
889906 Ok ( true ) => Some ( vec ! [ ] ) ,
890907 Ok ( false ) => None ,
0 commit comments