@@ -575,47 +575,25 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
575
575
}
576
576
}
577
577
578
- #[ derive( Clone , Debug ) ]
578
+ #[ derive( Clone , Debug , PartialEq ) ]
579
579
enum Constructor < ' tcx > {
580
580
/// The constructor of all patterns that don't vary by constructor,
581
581
/// e.g., struct patterns and fixed-length arrays.
582
582
Single ,
583
583
/// Enum variants.
584
584
Variant ( DefId ) ,
585
585
/// Literal values.
586
- ConstantValue ( & ' tcx ty:: Const < ' tcx > , Span ) ,
586
+ ConstantValue ( & ' tcx ty:: Const < ' tcx > ) ,
587
587
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
588
588
IntRange ( IntRange < ' tcx > ) ,
589
589
/// Ranges of non-integer literal values (`2.0..=5.2`).
590
- ConstantRange ( & ' tcx ty:: Const < ' tcx > , & ' tcx ty:: Const < ' tcx > , Ty < ' tcx > , RangeEnd , Span ) ,
590
+ ConstantRange ( & ' tcx ty:: Const < ' tcx > , & ' tcx ty:: Const < ' tcx > , RangeEnd ) ,
591
591
/// Array patterns of length `n`.
592
592
FixedLenSlice ( u64 ) ,
593
593
/// Slice patterns. Captures any array constructor of `length >= i + j`.
594
594
VarLenSlice ( u64 , u64 ) ,
595
595
}
596
596
597
- // Ignore spans when comparing, they don't carry semantic information as they are only for lints.
598
- impl < ' tcx > std:: cmp:: PartialEq for Constructor < ' tcx > {
599
- fn eq ( & self , other : & Self ) -> bool {
600
- match ( self , other) {
601
- ( Constructor :: Single , Constructor :: Single ) => true ,
602
- ( Constructor :: Variant ( a) , Constructor :: Variant ( b) ) => a == b,
603
- ( Constructor :: ConstantValue ( a, _) , Constructor :: ConstantValue ( b, _) ) => a == b,
604
- (
605
- Constructor :: ConstantRange ( a_start, a_end, a_ty, a_range_end, _) ,
606
- Constructor :: ConstantRange ( b_start, b_end, b_ty, b_range_end, _) ,
607
- ) => a_start == b_start && a_end == b_end && a_ty == b_ty && a_range_end == b_range_end,
608
- ( Constructor :: IntRange ( a) , Constructor :: IntRange ( b) ) => a == b,
609
- ( Constructor :: FixedLenSlice ( a) , Constructor :: FixedLenSlice ( b) ) => a == b,
610
- (
611
- Constructor :: VarLenSlice ( a_prefix, a_suffix) ,
612
- Constructor :: VarLenSlice ( b_prefix, b_suffix) ,
613
- ) => a_prefix == b_prefix && a_suffix == b_suffix,
614
- _ => false ,
615
- }
616
- }
617
- }
618
-
619
597
impl < ' tcx > Constructor < ' tcx > {
620
598
fn is_slice ( & self ) -> bool {
621
599
match self {
@@ -642,7 +620,7 @@ impl<'tcx> Constructor<'tcx> {
642
620
assert ! ( !adt. is_enum( ) ) ;
643
621
VariantIdx :: new ( 0 )
644
622
}
645
- ConstantValue ( c, _ ) => crate :: const_eval:: const_variant_index ( cx. tcx , cx. param_env , c) ,
623
+ ConstantValue ( c) => crate :: const_eval:: const_variant_index ( cx. tcx , cx. param_env , c) ,
646
624
_ => bug ! ( "bad constructor {:?} for adt {:?}" , self , adt) ,
647
625
}
648
626
}
@@ -925,8 +903,8 @@ impl<'tcx> Constructor<'tcx> {
925
903
} ,
926
904
927
905
_ => match * self {
928
- ConstantValue ( value, _ ) => PatKind :: Constant { value } ,
929
- ConstantRange ( lo, hi, _ , end, _ ) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
906
+ ConstantValue ( value) => PatKind :: Constant { value } ,
907
+ ConstantRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
930
908
IntRange ( ref range) => {
931
909
return range. to_pat ( cx. tcx ) ;
932
910
}
@@ -1136,10 +1114,9 @@ fn all_constructors<'a, 'tcx>(
1136
1114
)
1137
1115
} ;
1138
1116
let ctors = match pcx. ty . kind {
1139
- ty:: Bool => [ true , false ]
1140
- . iter ( )
1141
- . map ( |& b| ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) , pcx. span ) )
1142
- . collect ( ) ,
1117
+ ty:: Bool => {
1118
+ [ true , false ] . iter ( ) . map ( |& b| ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) ) ) . collect ( )
1119
+ }
1143
1120
ty:: Array ( ref sub_ty, len) if len. try_eval_usize ( cx. tcx , cx. param_env ) . is_some ( ) => {
1144
1121
let len = len. eval_usize ( cx. tcx , cx. param_env ) ;
1145
1122
if len != 0 && cx. is_uninhabited ( sub_ty) { vec ! [ ] } else { vec ! [ FixedLenSlice ( len) ] }
@@ -1710,7 +1687,7 @@ fn pat_constructor<'tcx>(
1710
1687
if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
1711
1688
Some ( IntRange ( int_range) )
1712
1689
} else {
1713
- Some ( ConstantValue ( value, pat . span ) )
1690
+ Some ( ConstantValue ( value) )
1714
1691
}
1715
1692
}
1716
1693
PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -1725,7 +1702,7 @@ fn pat_constructor<'tcx>(
1725
1702
) {
1726
1703
Some ( IntRange ( int_range) )
1727
1704
} else {
1728
- Some ( ConstantRange ( lo, hi, ty , end, pat . span ) )
1705
+ Some ( ConstantRange ( lo, hi, end) )
1729
1706
}
1730
1707
}
1731
1708
PatKind :: Array { .. } => match pat. ty . kind {
@@ -2110,8 +2087,8 @@ fn constructor_covered_by_range<'tcx>(
2110
2087
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , pat) ,
2111
2088
} ;
2112
2089
let ( ctor_from, ctor_to, ctor_end) = match * ctor {
2113
- ConstantValue ( value, _ ) => ( value, value, RangeEnd :: Included ) ,
2114
- ConstantRange ( from, to, _ , ctor_end, _ ) => ( from, to, ctor_end) ,
2090
+ ConstantValue ( value) => ( value, value, RangeEnd :: Included ) ,
2091
+ ConstantRange ( from, to, ctor_end) => ( from, to, ctor_end) ,
2115
2092
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , ctor) ,
2116
2093
} ;
2117
2094
trace ! ( "constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}" , ctor, pat_from, pat_to, ty) ;
@@ -2300,7 +2277,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
2300
2277
None
2301
2278
}
2302
2279
}
2303
- ConstantValue ( cv, _ ) => {
2280
+ ConstantValue ( cv) => {
2304
2281
match slice_pat_covered_by_const (
2305
2282
cx. tcx ,
2306
2283
pat. span ,
0 commit comments