@@ -2698,30 +2698,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2698
2698
hir:: TyKind :: Pat ( ty, pat) => {
2699
2699
let ty_span = ty. span ;
2700
2700
let ty = self . lower_ty ( ty) ;
2701
- let pat_ty = match pat. kind {
2702
- hir:: TyPatKind :: Range ( start, end) => {
2703
- let ( ty, start, end) = match ty. kind ( ) {
2704
- // Keep this list of types in sync with the list of types that
2705
- // the `RangePattern` trait is implemented for.
2706
- ty:: Int ( _) | ty:: Uint ( _) | ty:: Char => {
2707
- let start = self . lower_const_arg ( start, FeedConstTy :: No ) ;
2708
- let end = self . lower_const_arg ( end, FeedConstTy :: No ) ;
2709
- ( ty, start, end)
2710
- }
2711
- _ => {
2712
- let guar = self . dcx ( ) . span_delayed_bug (
2713
- ty_span,
2714
- "invalid base type for range pattern" ,
2715
- ) ;
2716
- let errc = ty:: Const :: new_error ( tcx, guar) ;
2717
- ( Ty :: new_error ( tcx, guar) , errc, errc)
2718
- }
2719
- } ;
2720
-
2721
- let pat = tcx. mk_pat ( ty:: PatternKind :: Range { start, end } ) ;
2722
- Ty :: new_pat ( tcx, ty, pat)
2723
- }
2724
- hir:: TyPatKind :: Err ( e) => Ty :: new_error ( tcx, e) ,
2701
+ let pat_ty = match self . lower_pat_ty_pat ( ty, ty_span, pat) {
2702
+ Ok ( kind) => Ty :: new_pat ( tcx, ty, tcx. mk_pat ( kind) ) ,
2703
+ Err ( guar) => Ty :: new_error ( tcx, guar) ,
2725
2704
} ;
2726
2705
self . record_ty ( pat. hir_id , ty, pat. span ) ;
2727
2706
pat_ty
@@ -2733,6 +2712,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2733
2712
result_ty
2734
2713
}
2735
2714
2715
+ fn lower_pat_ty_pat (
2716
+ & self ,
2717
+ ty : Ty < ' tcx > ,
2718
+ ty_span : Span ,
2719
+ pat : & hir:: TyPat < ' tcx > ,
2720
+ ) -> Result < ty:: PatternKind < ' tcx > , ErrorGuaranteed > {
2721
+ match pat. kind {
2722
+ hir:: TyPatKind :: Range ( start, end) => {
2723
+ match ty. kind ( ) {
2724
+ // Keep this list of types in sync with the list of types that
2725
+ // the `RangePattern` trait is implemented for.
2726
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Char => {
2727
+ let start = self . lower_const_arg ( start, FeedConstTy :: No ) ;
2728
+ let end = self . lower_const_arg ( end, FeedConstTy :: No ) ;
2729
+ Ok ( ty:: PatternKind :: Range { start, end } )
2730
+ }
2731
+ _ => Err ( self
2732
+ . dcx ( )
2733
+ . span_delayed_bug ( ty_span, "invalid base type for range pattern" ) ) ,
2734
+ }
2735
+ }
2736
+ hir:: TyPatKind :: Err ( e) => Err ( e) ,
2737
+ }
2738
+ }
2739
+
2736
2740
/// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
2737
2741
#[ instrument( level = "debug" , skip( self ) , ret) ]
2738
2742
fn lower_opaque_ty ( & self , def_id : LocalDefId , in_trait : bool ) -> Ty < ' tcx > {
0 commit comments