@@ -617,43 +617,41 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
617
617
expr : & ' tcx hir:: PatExpr < ' tcx > ,
618
618
pat_ty : Option < Ty < ' tcx > > ,
619
619
) -> PatKind < ' tcx > {
620
- let ( lit, neg) = match & expr. kind {
621
- hir:: PatExprKind :: Path ( qpath) => {
622
- return self . lower_path ( qpath, expr. hir_id , expr. span ) . kind ;
623
- }
620
+ match & expr. kind {
621
+ hir:: PatExprKind :: Path ( qpath) => self . lower_path ( qpath, expr. hir_id , expr. span ) . kind ,
624
622
hir:: PatExprKind :: ConstBlock ( anon_const) => {
625
- return self . lower_inline_const ( anon_const, expr. hir_id , expr. span ) ;
623
+ self . lower_inline_const ( anon_const, expr. hir_id , expr. span )
626
624
}
627
- hir:: PatExprKind :: Lit { lit, negated } => ( lit, * negated) ,
628
- } ;
629
-
630
- // We handle byte string literal patterns by using the pattern's type instead of the
631
- // literal's type in `const_to_pat`: if the literal `b"..."` matches on a slice reference,
632
- // the pattern's type will be `&[u8]` whereas the literal's type is `&[u8; 3]`; using the
633
- // pattern's type means we'll properly translate it to a slice reference pattern. This works
634
- // because slices and arrays have the same valtree representation.
635
- // HACK: As an exception, use the literal's type if `pat_ty` is `String`; this can happen if
636
- // `string_deref_patterns` is enabled. There's a special case for that when lowering to MIR.
637
- // FIXME(deref_patterns): This hack won't be necessary once `string_deref_patterns` is
638
- // superseded by a more general implementation of deref patterns.
639
- let ct_ty = match pat_ty {
640
- Some ( pat_ty)
641
- if let ty:: Adt ( def, _) = * pat_ty. kind ( )
642
- && self . tcx . is_lang_item ( def. did ( ) , LangItem :: String ) =>
643
- {
644
- if !self . tcx . features ( ) . string_deref_patterns ( ) {
645
- span_bug ! (
646
- expr. span,
647
- "matching on `String` went through without enabling string_deref_patterns"
648
- ) ;
649
- }
650
- self . typeck_results . node_type ( expr. hir_id )
625
+ hir:: PatExprKind :: Lit { lit, negated } => {
626
+ // We handle byte string literal patterns by using the pattern's type instead of the
627
+ // literal's type in `const_to_pat`: if the literal `b"..."` matches on a slice reference,
628
+ // the pattern's type will be `&[u8]` whereas the literal's type is `&[u8; 3]`; using the
629
+ // pattern's type means we'll properly translate it to a slice reference pattern. This works
630
+ // because slices and arrays have the same valtree representation.
631
+ // HACK: As an exception, use the literal's type if `pat_ty` is `String`; this can happen if
632
+ // `string_deref_patterns` is enabled. There's a special case for that when lowering to MIR.
633
+ // FIXME(deref_patterns): This hack won't be necessary once `string_deref_patterns` is
634
+ // superseded by a more general implementation of deref patterns.
635
+ let ct_ty = match pat_ty {
636
+ Some ( pat_ty)
637
+ if let ty:: Adt ( def, _) = * pat_ty. kind ( )
638
+ && self . tcx . is_lang_item ( def. did ( ) , LangItem :: String ) =>
639
+ {
640
+ if !self . tcx . features ( ) . string_deref_patterns ( ) {
641
+ span_bug ! (
642
+ expr. span,
643
+ "matching on `String` went through without enabling string_deref_patterns"
644
+ ) ;
645
+ }
646
+ self . typeck_results . node_type ( expr. hir_id )
647
+ }
648
+ Some ( pat_ty) => pat_ty,
649
+ None => self . typeck_results . node_type ( expr. hir_id ) ,
650
+ } ;
651
+ let lit_input = LitToConstInput { lit : & lit. node , ty : ct_ty, neg : * negated } ;
652
+ let constant = self . tcx . at ( expr. span ) . lit_to_const ( lit_input) ;
653
+ self . const_to_pat ( constant, ct_ty, expr. hir_id , lit. span ) . kind
651
654
}
652
- Some ( pat_ty) => pat_ty,
653
- None => self . typeck_results . node_type ( expr. hir_id ) ,
654
- } ;
655
- let lit_input = LitToConstInput { lit : & lit. node , ty : ct_ty, neg } ;
656
- let constant = self . tcx . at ( expr. span ) . lit_to_const ( lit_input) ;
657
- self . const_to_pat ( constant, ct_ty, expr. hir_id , lit. span ) . kind
655
+ }
658
656
}
659
657
}
0 commit comments