@@ -2715,30 +2715,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2715
2715
hir:: TyKind :: Pat ( ty, pat) => {
2716
2716
let ty_span = ty. span ;
2717
2717
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) ,
2742
2721
} ;
2743
2722
self . record_ty ( pat. hir_id , ty, pat. span ) ;
2744
2723
pat_ty
@@ -2750,6 +2729,39 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2750
2729
result_ty
2751
2730
}
2752
2731
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
+ let tcx = self . tcx ( ) ;
2739
+ match pat. kind {
2740
+ hir:: TyPatKind :: Range ( start, end) => {
2741
+ match ty. kind ( ) {
2742
+ // Keep this list of types in sync with the list of types that
2743
+ // the `RangePattern` trait is implemented for.
2744
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Char => {
2745
+ let start = self . lower_const_arg ( start, FeedConstTy :: No ) ;
2746
+ let end = self . lower_const_arg ( end, FeedConstTy :: No ) ;
2747
+ Ok ( ty:: PatternKind :: Range { start, end } )
2748
+ }
2749
+ _ => Err ( self
2750
+ . dcx ( )
2751
+ . span_delayed_bug ( ty_span, "invalid base type for range pattern" ) ) ,
2752
+ }
2753
+ }
2754
+ hir:: TyPatKind :: Or ( patterns) => {
2755
+ self . tcx ( )
2756
+ . mk_patterns_from_iter ( patterns. iter ( ) . map ( |pat| {
2757
+ self . lower_pat_ty_pat ( ty, ty_span, pat) . map ( |pat| tcx. mk_pat ( pat) )
2758
+ } ) )
2759
+ . map ( ty:: PatternKind :: Or )
2760
+ }
2761
+ hir:: TyPatKind :: Err ( e) => Err ( e) ,
2762
+ }
2763
+ }
2764
+
2753
2765
/// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
2754
2766
#[ instrument( level = "debug" , skip( self ) , ret) ]
2755
2767
fn lower_opaque_ty ( & self , def_id : LocalDefId , in_trait : bool ) -> Ty < ' tcx > {
0 commit comments