@@ -820,8 +820,8 @@ enum Constructor<'tcx> {
820820 Single ,
821821 /// Enum variants.
822822 Variant ( DefId ) ,
823- /// Literal values.
824- ConstantValue ( & ' tcx ty:: Const < ' tcx > ) ,
823+ /// String literals
824+ Str ( & ' tcx ty:: Const < ' tcx > ) ,
825825 /// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
826826 IntRange ( IntRange < ' tcx > ) ,
827827 /// Ranges of floating-point literal values (`2.0..=5.2`).
@@ -840,22 +840,13 @@ impl<'tcx> Constructor<'tcx> {
840840 }
841841 }
842842
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 {
848844 match * self {
849845 Variant ( id) => adt. variant_index_with_id ( id) ,
850846 Single => {
851847 assert ! ( !adt. is_enum( ) ) ;
852848 VariantIdx :: new ( 0 )
853849 }
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" ) ,
859850 _ => bug ! ( "bad constructor {:?} for adt {:?}" , self , adt) ,
860851 }
861852 }
@@ -869,7 +860,7 @@ impl<'tcx> Constructor<'tcx> {
869860
870861 match self {
871862 // Those constructors can only match themselves.
872- Single | Variant ( _) | ConstantValue ( .. ) | FloatRange ( ..) => {
863+ Single | Variant ( _) | Str ( _ ) | FloatRange ( ..) => {
873864 if other_ctors. iter ( ) . any ( |c| c == self ) { vec ! [ ] } else { vec ! [ self . clone( ) ] }
874865 }
875866 & Slice ( slice) => {
@@ -979,7 +970,7 @@ impl<'tcx> Constructor<'tcx> {
979970 PatKind :: Variant {
980971 adt_def : adt,
981972 substs,
982- variant_index : self . variant_index_for_adt ( cx , adt) ,
973+ variant_index : self . variant_index_for_adt ( adt) ,
983974 subpatterns,
984975 }
985976 } else {
@@ -1018,7 +1009,7 @@ impl<'tcx> Constructor<'tcx> {
10181009 PatKind :: Slice { prefix, slice : Some ( wild) , suffix }
10191010 }
10201011 } ,
1021- & ConstantValue ( value) => PatKind :: Constant { value } ,
1012+ & Str ( value) => PatKind :: Constant { value } ,
10221013 & FloatRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
10231014 IntRange ( range) => return range. to_pat ( cx. tcx ) ,
10241015 NonExhaustive => PatKind :: Wild ,
@@ -1125,7 +1116,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11251116 // Use T as the sub pattern type of Box<T>.
11261117 Fields :: from_single_pattern ( wildcard_from_ty ( substs. type_at ( 0 ) ) )
11271118 } else {
1128- let variant = & adt. variants [ constructor. variant_index_for_adt ( cx , adt) ] ;
1119+ let variant = & adt. variants [ constructor. variant_index_for_adt ( adt) ] ;
11291120 // Whether we must not match the fields of this variant exhaustively.
11301121 let is_non_exhaustive =
11311122 variant. is_field_list_non_exhaustive ( ) && !adt. did . is_local ( ) ;
@@ -1173,7 +1164,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11731164 }
11741165 _ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, ty) ,
11751166 } ,
1176- ConstantValue ( .. ) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
1167+ Str ( _ ) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
11771168 } ;
11781169 debug ! ( "Fields::wildcards({:?}, {:?}) = {:#?}" , constructor, ty, ret) ;
11791170 ret
@@ -2110,7 +2101,12 @@ fn pat_constructor<'tcx>(
21102101 if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
21112102 Some ( IntRange ( int_range) )
21122103 } 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+ }
21142110 }
21152111 }
21162112 PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -2458,7 +2454,7 @@ fn constructor_covered_by_range<'tcx>(
24582454 _ => bug ! ( "`constructor_covered_by_range` called with {:?}" , pat) ,
24592455 } ;
24602456 let ( ctor_from, ctor_to, ctor_end) = match * ctor {
2461- ConstantValue ( value) => ( value, value, RangeEnd :: Included ) ,
2457+ Str ( value) => ( value, value, RangeEnd :: Included ) ,
24622458 FloatRange ( from, to, ctor_end) => ( from, to, ctor_end) ,
24632459 _ => bug ! ( "`constructor_covered_by_range` called with {:?}" , ctor) ,
24642460 } ;
@@ -2558,7 +2554,7 @@ fn specialize_one_pattern<'p, 'tcx>(
25582554 let suffix = suffix. iter ( ) . enumerate ( ) . map ( |( i, p) | ( arity - suffix. len ( ) + i, p) ) ;
25592555 Some ( ctor_wild_subpatterns. replace_fields_indexed ( prefix. chain ( suffix) ) )
25602556 }
2561- ConstantValue ( _) => None ,
2557+ Str ( _) => None ,
25622558 _ => span_bug ! ( pat. span, "unexpected ctor {:?} for slice pat" , constructor) ,
25632559 } ,
25642560
0 commit comments