@@ -827,6 +827,8 @@ enum Constructor<'tcx> {
827827 IntRange ( IntRange < ' tcx > ) ,
828828 /// Ranges of floating-point literal values (`2.0..=5.2`).
829829 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 > ) ,
830832 /// Array and slice patterns.
831833 Slice ( Slice ) ,
832834 /// Fake extra constructor for enums that aren't allowed to be matched exhaustively.
@@ -863,7 +865,7 @@ impl<'tcx> Constructor<'tcx> {
863865
864866 match self {
865867 // Those constructors can only match themselves.
866- Single | Variant ( _) | ConstantValue ( ..) | FloatRange ( ..) => {
868+ Single | Variant ( _) | ConstantValue ( ..) | Str ( .. ) | FloatRange ( ..) => {
867869 if other_ctors. iter ( ) . any ( |c| c == self ) { vec ! [ ] } else { vec ! [ self . clone( ) ] }
868870 }
869871 & Slice ( slice) => {
@@ -1013,6 +1015,7 @@ impl<'tcx> Constructor<'tcx> {
10131015 }
10141016 } ,
10151017 & ConstantValue ( value) => PatKind :: Constant { value } ,
1018+ & Str ( value) => PatKind :: Constant { value } ,
10161019 & FloatRange ( lo, hi, end) => PatKind :: Range ( PatRange { lo, hi, end } ) ,
10171020 IntRange ( range) => return range. to_pat ( cx. tcx ) ,
10181021 NonExhaustive => PatKind :: Wild ,
@@ -1167,7 +1170,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11671170 }
11681171 _ => bug ! ( "bad slice pattern {:?} {:?}" , constructor, ty) ,
11691172 } ,
1170- ConstantValue ( ..) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => Fields :: empty ( ) ,
1173+ ConstantValue ( ..) | Str ( ..) | FloatRange ( ..) | IntRange ( ..) | NonExhaustive => {
1174+ Fields :: empty ( )
1175+ }
11711176 } ;
11721177 debug ! ( "Fields::wildcards({:?}, {:?}) = {:#?}" , constructor, ty, ret) ;
11731178 ret
@@ -2106,6 +2111,7 @@ fn pat_constructor<'tcx>(
21062111 } else {
21072112 match value. ty . kind ( ) {
21082113 ty:: Float ( _) => Some ( FloatRange ( value, value, RangeEnd :: Included ) ) ,
2114+ ty:: Ref ( _, t, _) if t. is_str ( ) => Some ( Str ( value) ) ,
21092115 _ => Some ( ConstantValue ( value) ) ,
21102116 }
21112117 }
@@ -2508,7 +2514,7 @@ fn specialize_one_pattern<'p, 'tcx>(
25082514 return None ;
25092515 }
25102516 }
2511- ConstantValue ( ctor_value) => {
2517+ ConstantValue ( ctor_value) | Str ( ctor_value ) => {
25122518 let pat_value = match * pat. kind {
25132519 PatKind :: Constant { value } => value,
25142520 _ => span_bug ! (
0 commit comments