@@ -582,19 +582,19 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
582
582
}
583
583
}
584
584
585
- #[ derive( Clone , Debug ) ]
585
+ #[ derive( Clone , Debug , PartialEq ) ]
586
586
enum Constructor < ' tcx > {
587
587
/// The constructor of all patterns that don't vary by constructor,
588
588
/// e.g., struct patterns and fixed-length arrays.
589
589
Single ,
590
590
/// Enum variants.
591
591
Variant ( DefId ) ,
592
592
/// Literal values.
593
- ConstantValue ( & ' tcx ty:: Const < ' tcx > , Span ) ,
593
+ ConstantValue ( & ' tcx ty:: Const < ' tcx > ) ,
594
594
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
595
595
IntRange ( IntRange < ' tcx > ) ,
596
596
/// Ranges of non-integer literal values (`2.0..=5.2`).
597
- ConstantRange ( & ' tcx ty:: Const < ' tcx > , & ' tcx ty:: Const < ' tcx > , Ty < ' tcx > , RangeEnd , Span ) ,
597
+ ConstantRange ( & ' tcx ty:: Const < ' tcx > , & ' tcx ty:: Const < ' tcx > , RangeEnd ) ,
598
598
/// Array patterns of length `n`.
599
599
FixedLenSlice ( u64 ) ,
600
600
/// Slice patterns. Captures any array constructor of `length >= i + j`.
@@ -603,29 +603,6 @@ enum Constructor<'tcx> {
603
603
NonExhaustive ,
604
604
}
605
605
606
- // Ignore spans when comparing, they don't carry semantic information as they are only for lints.
607
- impl < ' tcx > std:: cmp:: PartialEq for Constructor < ' tcx > {
608
- fn eq ( & self , other : & Self ) -> bool {
609
- match ( self , other) {
610
- ( Constructor :: Single , Constructor :: Single ) => true ,
611
- ( Constructor :: NonExhaustive , Constructor :: NonExhaustive ) => true ,
612
- ( Constructor :: Variant ( a) , Constructor :: Variant ( b) ) => a == b,
613
- ( Constructor :: ConstantValue ( a, _) , Constructor :: ConstantValue ( b, _) ) => a == b,
614
- (
615
- Constructor :: ConstantRange ( a_start, a_end, a_ty, a_range_end, _) ,
616
- Constructor :: ConstantRange ( b_start, b_end, b_ty, b_range_end, _) ,
617
- ) => a_start == b_start && a_end == b_end && a_ty == b_ty && a_range_end == b_range_end,
618
- ( Constructor :: IntRange ( a) , Constructor :: IntRange ( b) ) => a == b,
619
- ( Constructor :: FixedLenSlice ( a) , Constructor :: FixedLenSlice ( b) ) => a == b,
620
- (
621
- Constructor :: VarLenSlice ( a_prefix, a_suffix) ,
622
- Constructor :: VarLenSlice ( b_prefix, b_suffix) ,
623
- ) => a_prefix == b_prefix && a_suffix == b_suffix,
624
- _ => false ,
625
- }
626
- }
627
- }
628
-
629
606
impl < ' tcx > Constructor < ' tcx > {
630
607
fn is_slice ( & self ) -> bool {
631
608
match self {
@@ -652,7 +629,7 @@ impl<'tcx> Constructor<'tcx> {
652
629
assert ! ( !adt. is_enum( ) ) ;
653
630
VariantIdx :: new ( 0 )
654
631
}
655
- ConstantValue ( c, _ ) => crate :: const_eval:: const_variant_index ( cx. tcx , cx. param_env , c) ,
632
+ ConstantValue ( c) => crate :: const_eval:: const_variant_index ( cx. tcx , cx. param_env , c) ,
656
633
_ => bug ! ( "bad constructor {:?} for adt {:?}" , self , adt) ,
657
634
}
658
635
}
@@ -938,8 +915,8 @@ impl<'tcx> Constructor<'tcx> {
938
915
let wild = Pat :: wildcard_from_ty ( ty) ;
939
916
PatKind :: Slice { prefix, slice : Some ( wild) , suffix }
940
917
}
941
- & ConstantValue ( value, _ ) => PatKind :: Constant { value } ,
942
- & ConstantRange ( lo, hi, _ , end, _ ) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
918
+ & ConstantValue ( value) => PatKind :: Constant { value } ,
919
+ & ConstantRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
943
920
IntRange ( range) => {
944
921
return range. to_pat ( cx. tcx ) ;
945
922
}
@@ -1148,10 +1125,9 @@ fn all_constructors<'a, 'tcx>(
1148
1125
)
1149
1126
} ;
1150
1127
match pcx. ty . kind {
1151
- ty:: Bool => [ true , false ]
1152
- . iter ( )
1153
- . map ( |& b| ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) , pcx. span ) )
1154
- . collect ( ) ,
1128
+ ty:: Bool => {
1129
+ [ true , false ] . iter ( ) . map ( |& b| ConstantValue ( ty:: Const :: from_bool ( cx. tcx , b) ) ) . collect ( )
1130
+ }
1155
1131
ty:: Array ( ref sub_ty, len) if len. try_eval_usize ( cx. tcx , cx. param_env ) . is_some ( ) => {
1156
1132
let len = len. eval_usize ( cx. tcx , cx. param_env ) ;
1157
1133
if len != 0 && cx. is_uninhabited ( sub_ty) { vec ! [ ] } else { vec ! [ FixedLenSlice ( len) ] }
@@ -1721,7 +1697,7 @@ fn pat_constructor<'tcx>(
1721
1697
if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
1722
1698
Some ( IntRange ( int_range) )
1723
1699
} else {
1724
- Some ( ConstantValue ( value, pat . span ) )
1700
+ Some ( ConstantValue ( value) )
1725
1701
}
1726
1702
}
1727
1703
PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -1736,7 +1712,7 @@ fn pat_constructor<'tcx>(
1736
1712
) {
1737
1713
Some ( IntRange ( int_range) )
1738
1714
} else {
1739
- Some ( ConstantRange ( lo, hi, ty , end, pat . span ) )
1715
+ Some ( ConstantRange ( lo, hi, end) )
1740
1716
}
1741
1717
}
1742
1718
PatKind :: Array { .. } => match pat. ty . kind {
@@ -2134,8 +2110,8 @@ fn constructor_covered_by_range<'tcx>(
2134
2110
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , pat) ,
2135
2111
} ;
2136
2112
let ( ctor_from, ctor_to, ctor_end) = match * ctor {
2137
- ConstantValue ( value, _ ) => ( value, value, RangeEnd :: Included ) ,
2138
- ConstantRange ( from, to, _ , ctor_end, _ ) => ( from, to, ctor_end) ,
2113
+ ConstantValue ( value) => ( value, value, RangeEnd :: Included ) ,
2114
+ ConstantRange ( from, to, ctor_end) => ( from, to, ctor_end) ,
2139
2115
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , ctor) ,
2140
2116
} ;
2141
2117
trace ! ( "constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}" , ctor, pat_from, pat_to, ty) ;
@@ -2331,7 +2307,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
2331
2307
None
2332
2308
}
2333
2309
}
2334
- ConstantValue ( cv, _ ) => {
2310
+ ConstantValue ( cv) => {
2335
2311
match slice_pat_covered_by_const (
2336
2312
cx. tcx ,
2337
2313
pat. span ,
0 commit comments