@@ -820,8 +820,8 @@ enum Constructor<'tcx> {
820
820
Single ,
821
821
/// Enum variants.
822
822
Variant ( DefId ) ,
823
- /// Literal values.
824
- ConstantValue ( & ' tcx ty:: Const < ' tcx > ) ,
823
+ /// String literals
824
+ Str ( & ' tcx ty:: Const < ' tcx > ) ,
825
825
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
826
826
IntRange ( IntRange < ' tcx > ) ,
827
827
/// Ranges of floating-point literal values (`2.0..=5.2`).
@@ -840,22 +840,13 @@ impl<'tcx> Constructor<'tcx> {
840
840
}
841
841
}
842
842
843
- fn variant_index_for_adt < ' a > (
844
- & self ,
845
- cx : & MatchCheckCtxt < ' a , ' tcx > ,
846
- adt : & ' tcx ty:: AdtDef ,
847
- ) -> VariantIdx {
843
+ fn variant_index_for_adt ( & self , adt : & ' tcx ty:: AdtDef ) -> VariantIdx {
848
844
match * self {
849
845
Variant ( id) => adt. variant_index_with_id ( id) ,
850
846
Single => {
851
847
assert ! ( !adt. is_enum( ) ) ;
852
848
VariantIdx :: new ( 0 )
853
849
}
854
- ConstantValue ( c) => cx
855
- . tcx
856
- . destructure_const ( cx. param_env . and ( c) )
857
- . variant
858
- . expect ( "destructed const of adt without variant id" ) ,
859
850
_ => bug ! ( "bad constructor {:?} for adt {:?}" , self , adt) ,
860
851
}
861
852
}
@@ -869,7 +860,7 @@ impl<'tcx> Constructor<'tcx> {
869
860
870
861
match self {
871
862
// Those constructors can only match themselves.
872
- Single | Variant ( _) | ConstantValue ( .. ) | FloatRange ( ..) => {
863
+ Single | Variant ( _) | Str ( _ ) | FloatRange ( ..) => {
873
864
if other_ctors. iter ( ) . any ( |c| c == self ) { vec ! [ ] } else { vec ! [ self . clone( ) ] }
874
865
}
875
866
& Slice ( slice) => {
@@ -979,7 +970,7 @@ impl<'tcx> Constructor<'tcx> {
979
970
PatKind :: Variant {
980
971
adt_def : adt,
981
972
substs,
982
- variant_index : self . variant_index_for_adt ( cx , adt) ,
973
+ variant_index : self . variant_index_for_adt ( adt) ,
983
974
subpatterns,
984
975
}
985
976
} else {
@@ -1018,7 +1009,7 @@ impl<'tcx> Constructor<'tcx> {
1018
1009
PatKind :: Slice { prefix, slice : Some ( wild) , suffix }
1019
1010
}
1020
1011
} ,
1021
- & ConstantValue ( value) => PatKind :: Constant { value } ,
1012
+ & Str ( value) => PatKind :: Constant { value } ,
1022
1013
& FloatRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
1023
1014
IntRange ( range) => return range. to_pat ( cx. tcx ) ,
1024
1015
NonExhaustive => PatKind :: Wild ,
@@ -1125,7 +1116,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1125
1116
// Use T as the sub pattern type of Box<T>.
1126
1117
Fields :: from_single_pattern ( wildcard_from_ty ( substs. type_at ( 0 ) ) )
1127
1118
} else {
1128
- let variant = & adt. variants [ constructor. variant_index_for_adt ( cx , adt) ] ;
1119
+ let variant = & adt. variants [ constructor. variant_index_for_adt ( adt) ] ;
1129
1120
// Whether we must not match the fields of this variant exhaustively.
1130
1121
let is_non_exhaustive =
1131
1122
variant. is_field_list_non_exhaustive ( ) && !adt. did . is_local ( ) ;
@@ -1173,7 +1164,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1173
1164
}
1174
1165
_ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, ty) ,
1175
1166
} ,
1176
- ConstantValue ( .. ) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
1167
+ Str ( _ ) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
1177
1168
} ;
1178
1169
debug ! ( "Fields::wildcards({:?}, {:?}) = {:#?}" , constructor, ty, ret) ;
1179
1170
ret
@@ -2110,7 +2101,12 @@ fn pat_constructor<'tcx>(
2110
2101
if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
2111
2102
Some ( IntRange ( int_range) )
2112
2103
} else {
2113
- Some ( ConstantValue ( value) )
2104
+ match value. ty . kind ( ) {
2105
+ ty:: Ref ( _, t, _) if t. is_str ( ) => Some ( Str ( value) ) ,
2106
+ ty:: Float ( _) => Some ( FloatRange ( value, value, RangeEnd :: Included ) ) ,
2107
+ // Non structural-match values are opaque.
2108
+ _ => None ,
2109
+ }
2114
2110
}
2115
2111
}
2116
2112
PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -2458,7 +2454,7 @@ fn constructor_covered_by_range<'tcx>(
2458
2454
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , pat) ,
2459
2455
} ;
2460
2456
let ( ctor_from, ctor_to, ctor_end) = match * ctor {
2461
- ConstantValue ( value) => ( value, value, RangeEnd :: Included ) ,
2457
+ Str ( value) => ( value, value, RangeEnd :: Included ) ,
2462
2458
FloatRange ( from, to, ctor_end) => ( from, to, ctor_end) ,
2463
2459
_ => bug ! ( "`constructor_covered_by_range` called with {:?}" , ctor) ,
2464
2460
} ;
@@ -2558,7 +2554,7 @@ fn specialize_one_pattern<'p, 'tcx>(
2558
2554
let suffix = suffix. iter ( ) . enumerate ( ) . map ( |( i, p) | ( arity - suffix. len ( ) + i, p) ) ;
2559
2555
Some ( ctor_wild_subpatterns. replace_fields_indexed ( prefix. chain ( suffix) ) )
2560
2556
}
2561
- ConstantValue ( _) => None ,
2557
+ Str ( _) => None ,
2562
2558
_ => span_bug ! ( pat. span, "unexpected ctor {:?} for slice pat" , constructor) ,
2563
2559
} ,
2564
2560
0 commit comments