@@ -2715,30 +2715,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27152715 hir:: TyKind :: Pat ( ty, pat) => {
27162716 let ty_span = ty. span ;
27172717 let ty = self . lower_ty ( ty) ;
2718- let pat_ty = match pat. kind {
2719- hir:: TyPatKind :: Range ( start, end) => {
2720- let ( ty, start, end) = match ty. kind ( ) {
2721- // Keep this list of types in sync with the list of types that
2722- // the `RangePattern` trait is implemented for.
2723- ty:: Int ( _) | ty:: Uint ( _) | ty:: Char => {
2724- let start = self . lower_const_arg ( start, FeedConstTy :: No ) ;
2725- let end = self . lower_const_arg ( end, FeedConstTy :: No ) ;
2726- ( ty, start, end)
2727- }
2728- _ => {
2729- let guar = self . dcx ( ) . span_delayed_bug (
2730- ty_span,
2731- "invalid base type for range pattern" ,
2732- ) ;
2733- let errc = ty:: Const :: new_error ( tcx, guar) ;
2734- ( Ty :: new_error ( tcx, guar) , errc, errc)
2735- }
2736- } ;
2737-
2738- let pat = tcx. mk_pat ( ty:: PatternKind :: Range { start, end } ) ;
2739- Ty :: new_pat ( tcx, ty, pat)
2740- }
2741- hir:: TyPatKind :: Err ( e) => Ty :: new_error ( tcx, e) ,
2718+ let pat_ty = match self . lower_pat_ty_pat ( ty, ty_span, pat) {
2719+ Ok ( kind) => Ty :: new_pat ( tcx, ty, tcx. mk_pat ( kind) ) ,
2720+ Err ( guar) => Ty :: new_error ( tcx, guar) ,
27422721 } ;
27432722 self . record_ty ( pat. hir_id , ty, pat. span ) ;
27442723 pat_ty
@@ -2750,6 +2729,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27502729 result_ty
27512730 }
27522731
2732+ fn lower_pat_ty_pat (
2733+ & self ,
2734+ ty : Ty < ' tcx > ,
2735+ ty_span : Span ,
2736+ pat : & hir:: TyPat < ' tcx > ,
2737+ ) -> Result < ty:: PatternKind < ' tcx > , ErrorGuaranteed > {
2738+ match pat. kind {
2739+ hir:: TyPatKind :: Range ( start, end) => {
2740+ match ty. kind ( ) {
2741+ // Keep this list of types in sync with the list of types that
2742+ // the `RangePattern` trait is implemented for.
2743+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Char => {
2744+ let start = self . lower_const_arg ( start, FeedConstTy :: No ) ;
2745+ let end = self . lower_const_arg ( end, FeedConstTy :: No ) ;
2746+ Ok ( ty:: PatternKind :: Range { start, end } )
2747+ }
2748+ _ => Err ( self
2749+ . dcx ( )
2750+ . span_delayed_bug ( ty_span, "invalid base type for range pattern" ) ) ,
2751+ }
2752+ }
2753+ hir:: TyPatKind :: Err ( e) => Err ( e) ,
2754+ }
2755+ }
2756+
27532757 /// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
27542758 #[ instrument( level = "debug" , skip( self ) , ret) ]
27552759 fn lower_opaque_ty ( & self , def_id : LocalDefId , in_trait : bool ) -> Ty < ' tcx > {
0 commit comments