@@ -827,6 +827,8 @@ enum Constructor<'tcx> {
827
827
IntRange ( IntRange < ' tcx > ) ,
828
828
/// Ranges of floating-point literal values (`2.0..=5.2`).
829
829
FloatRange ( & ' tcx ty:: Const < ' tcx > , & ' tcx ty:: Const < ' tcx > , RangeEnd ) ,
830
+ /// String literals. Strings are not quite the same as `&[u8]` so we treat them separately.
831
+ Str ( & ' tcx ty:: Const < ' tcx > ) ,
830
832
/// Array and slice patterns.
831
833
Slice ( Slice ) ,
832
834
/// Fake extra constructor for enums that aren't allowed to be matched exhaustively.
@@ -863,7 +865,7 @@ impl<'tcx> Constructor<'tcx> {
863
865
864
866
match self {
865
867
// Those constructors can only match themselves.
866
- Single | Variant ( _) | ConstantValue ( ..) | FloatRange ( ..) => {
868
+ Single | Variant ( _) | ConstantValue ( ..) | Str ( .. ) | FloatRange ( ..) => {
867
869
if other_ctors. iter ( ) . any ( |c| c == self ) { vec ! [ ] } else { vec ! [ self . clone( ) ] }
868
870
}
869
871
& Slice ( slice) => {
@@ -1013,6 +1015,7 @@ impl<'tcx> Constructor<'tcx> {
1013
1015
}
1014
1016
} ,
1015
1017
& ConstantValue ( value) => PatKind :: Constant { value } ,
1018
+ & Str ( value) => PatKind :: Constant { value } ,
1016
1019
& FloatRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
1017
1020
IntRange ( range) => return range. to_pat ( cx. tcx ) ,
1018
1021
NonExhaustive => PatKind :: Wild ,
@@ -1167,7 +1170,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1167
1170
}
1168
1171
_ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, ty) ,
1169
1172
} ,
1170
- ConstantValue ( ..) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
1173
+ ConstantValue ( ..) | Str ( ..) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => {
1174
+ Fields :: empty ( )
1175
+ }
1171
1176
} ;
1172
1177
debug ! ( "Fields::wildcards({:?}, {:?}) = {:#?}" , constructor, ty, ret) ;
1173
1178
ret
@@ -2106,6 +2111,7 @@ fn pat_constructor<'tcx>(
2106
2111
} else {
2107
2112
match value. ty . kind ( ) {
2108
2113
ty:: Float ( _) => Some ( FloatRange ( value, value, RangeEnd :: Included ) ) ,
2114
+ ty:: Ref ( _, t, _) if t. is_str ( ) => Some ( Str ( value) ) ,
2109
2115
_ => Some ( ConstantValue ( value) ) ,
2110
2116
}
2111
2117
}
@@ -2508,7 +2514,7 @@ fn specialize_one_pattern<'p, 'tcx>(
2508
2514
return None ;
2509
2515
}
2510
2516
}
2511
- ConstantValue ( ctor_value) => {
2517
+ ConstantValue ( ctor_value) | Str ( ctor_value ) => {
2512
2518
let pat_value = match * pat. kind {
2513
2519
PatKind :: Constant { value } => value,
2514
2520
_ => span_bug ! (
0 commit comments