@@ -4,10 +4,10 @@ use rustc_ast::ptr::P;
44use rustc_ast:: * ;
55use rustc_data_structures:: stack:: ensure_sufficient_stack;
66use rustc_hir as hir;
7- use rustc_hir:: def:: { DefKind , Res } ;
7+ use rustc_hir:: def:: Res ;
88use rustc_middle:: span_bug;
99use rustc_span:: source_map:: { Spanned , respan} ;
10- use rustc_span:: { Ident , Span , kw } ;
10+ use rustc_span:: { Ident , Span } ;
1111
1212use super :: errors:: {
1313 ArbitraryExpressionInPattern , ExtraDoubleDot , MisplacedDoubleDot , SubTupleBinding ,
@@ -430,78 +430,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
430430 self . arena . alloc ( hir:: PatExpr { hir_id : self . lower_node_id ( expr. id ) , span, kind } )
431431 }
432432
433- pub ( crate ) fn lower_ty_pat ( & mut self , pattern : & Pat ) -> & ' hir hir:: TyPat < ' hir > {
433+ pub ( crate ) fn lower_ty_pat ( & mut self , pattern : & TyPat ) -> & ' hir hir:: TyPat < ' hir > {
434434 self . arena . alloc ( self . lower_ty_pat_mut ( pattern) )
435435 }
436436
437- fn lower_ty_pat_mut ( & mut self , mut pattern : & Pat ) -> hir:: TyPat < ' hir > {
437+ fn lower_ty_pat_mut ( & mut self , pattern : & TyPat ) -> hir:: TyPat < ' hir > {
438438 // loop here to avoid recursion
439439 let pat_hir_id = self . lower_node_id ( pattern. id ) ;
440- let node = loop {
441- match & pattern. kind {
442- PatKind :: Range ( e1, e2, Spanned { node : end, .. } ) => {
443- // FIXME(pattern_types): remove this closure and call `lower_const_arg` instead.
444- // That requires first modifying the AST to have const args here.
445- let mut lower_expr = |e : & Expr | -> & _ {
446- if let ExprKind :: Path ( None , path) = & e. kind
447- && let Some ( res) = self
448- . resolver
449- . get_partial_res ( e. id )
450- . and_then ( |partial_res| partial_res. full_res ( ) )
451- {
452- self . lower_const_path_to_const_arg ( path, res, e. id , e. span )
453- } else {
454- let node_id = self . next_node_id ( ) ;
455- let def_id = self . create_def (
456- self . current_hir_id_owner . def_id ,
457- node_id,
458- kw:: Empty ,
459- DefKind :: AnonConst ,
460- e. span ,
461- ) ;
462- let hir_id = self . lower_node_id ( node_id) ;
463- let ac = self . arena . alloc ( hir:: AnonConst {
464- def_id,
465- hir_id,
466- body : self . lower_const_body ( pattern. span , Some ( e) ) ,
467- span : self . lower_span ( pattern. span ) ,
468- } ) ;
469- self . arena . alloc ( hir:: ConstArg {
470- hir_id : self . next_id ( ) ,
471- kind : hir:: ConstArgKind :: Anon ( ac) ,
472- } )
473- }
474- } ;
475- break hir:: TyPatKind :: Range (
476- e1. as_deref ( ) . map ( |e| lower_expr ( e) ) ,
477- e2. as_deref ( ) . map ( |e| lower_expr ( e) ) ,
478- self . lower_range_end ( end, e2. is_some ( ) ) ,
479- ) ;
480- }
481- // return inner to be processed in next loop
482- PatKind :: Paren ( inner) => pattern = inner,
483- PatKind :: MacCall ( _) => panic ! ( "{:?} shouldn't exist here" , pattern. span) ,
484- PatKind :: Err ( guar) => break hir:: TyPatKind :: Err ( * guar) ,
485- PatKind :: Deref ( ..)
486- | PatKind :: Box ( ..)
487- | PatKind :: Or ( ..)
488- | PatKind :: Struct ( ..)
489- | PatKind :: TupleStruct ( ..)
490- | PatKind :: Tuple ( ..)
491- | PatKind :: Ref ( ..)
492- | PatKind :: Expr ( ..)
493- | PatKind :: Guard ( ..)
494- | PatKind :: Slice ( _)
495- | PatKind :: Ident ( ..)
496- | PatKind :: Path ( ..)
497- | PatKind :: Wild
498- | PatKind :: Never
499- | PatKind :: Rest => {
500- break hir:: TyPatKind :: Err (
501- self . dcx ( ) . span_err ( pattern. span , "pattern not supported in pattern types" ) ,
502- ) ;
503- }
504- }
440+ let node = match & pattern. kind {
441+ TyPatKind :: Range ( e1, e2, Spanned { node : end, .. } ) => hir:: TyPatKind :: Range (
442+ e1. as_deref ( ) . map ( |e| self . lower_anon_const_to_const_arg ( e) ) ,
443+ e2. as_deref ( ) . map ( |e| self . lower_anon_const_to_const_arg ( e) ) ,
444+ self . lower_range_end ( end, e2. is_some ( ) ) ,
445+ ) ,
446+ TyPatKind :: Err ( guar) => hir:: TyPatKind :: Err ( * guar) ,
505447 } ;
506448
507449 hir:: TyPat { hir_id : pat_hir_id, kind : node, span : self . lower_span ( pattern. span ) }
0 commit comments