@@ -2465,86 +2465,88 @@ impl<'a> LoweringContext<'a> {
24652465 }
24662466
24672467 fn lower_pat ( & mut self , p : & Pat ) -> P < hir:: Pat > {
2468- let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( p. id ) ;
2468+ let node = match p. node {
2469+ PatKind :: Wild => hir:: PatKind :: Wild ,
2470+ PatKind :: Ident ( ref binding_mode, pth1, ref sub) => {
2471+ match self . resolver . get_resolution ( p. id ) . map ( |d| d. base_def ( ) ) {
2472+ // `None` can occur in body-less function signatures
2473+ def @ None | def @ Some ( Def :: Local ( _) ) => {
2474+ let canonical_id = match def {
2475+ Some ( Def :: Local ( id) ) => id,
2476+ _ => p. id
2477+ } ;
2478+ hir:: PatKind :: Binding ( self . lower_binding_mode ( binding_mode) ,
2479+ canonical_id,
2480+ respan ( pth1. span , pth1. node . name ) ,
2481+ sub. as_ref ( ) . map ( |x| self . lower_pat ( x) ) )
2482+ }
2483+ Some ( def) => {
2484+ hir:: PatKind :: Path ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
2485+ span : pth1. span ,
2486+ def,
2487+ segments : hir_vec ! [
2488+ hir:: PathSegment :: from_name( pth1. node. name)
2489+ ] ,
2490+ } ) ) )
2491+ }
2492+ }
2493+ }
2494+ PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( P ( self . lower_expr ( e) ) ) ,
2495+ PatKind :: TupleStruct ( ref path, ref pats, ddpos) => {
2496+ let qpath = self . lower_qpath ( p. id , & None , path, ParamMode :: Optional ,
2497+ ImplTraitContext :: Disallowed ) ;
2498+ hir:: PatKind :: TupleStruct ( qpath,
2499+ pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
2500+ ddpos)
2501+ }
2502+ PatKind :: Path ( ref qself, ref path) => {
2503+ hir:: PatKind :: Path ( self . lower_qpath ( p. id , qself, path, ParamMode :: Optional ,
2504+ ImplTraitContext :: Disallowed ) )
2505+ }
2506+ PatKind :: Struct ( ref path, ref fields, etc) => {
2507+ let qpath = self . lower_qpath ( p. id , & None , path, ParamMode :: Optional ,
2508+ ImplTraitContext :: Disallowed ) ;
2509+
2510+ let fs = fields. iter ( )
2511+ . map ( |f| {
2512+ Spanned {
2513+ span : f. span ,
2514+ node : hir:: FieldPat {
2515+ name : self . lower_ident ( f. node . ident ) ,
2516+ pat : self . lower_pat ( & f. node . pat ) ,
2517+ is_shorthand : f. node . is_shorthand ,
2518+ } ,
2519+ }
2520+ } )
2521+ . collect ( ) ;
2522+ hir:: PatKind :: Struct ( qpath, fs, etc)
2523+ }
2524+ PatKind :: Tuple ( ref elts, ddpos) => {
2525+ hir:: PatKind :: Tuple ( elts. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) , ddpos)
2526+ }
2527+ PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
2528+ PatKind :: Ref ( ref inner, mutbl) => {
2529+ hir:: PatKind :: Ref ( self . lower_pat ( inner) , self . lower_mutability ( mutbl) )
2530+ }
2531+ PatKind :: Range ( ref e1, ref e2, ref end) => {
2532+ hir:: PatKind :: Range ( P ( self . lower_expr ( e1) ) ,
2533+ P ( self . lower_expr ( e2) ) ,
2534+ self . lower_range_end ( end) )
2535+ }
2536+ PatKind :: Slice ( ref before, ref slice, ref after) => {
2537+ hir:: PatKind :: Slice ( before. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
2538+ slice. as_ref ( ) . map ( |x| self . lower_pat ( x) ) ,
2539+ after. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) )
2540+ }
2541+ PatKind :: Paren ( ref inner) => return self . lower_pat ( inner) ,
2542+ PatKind :: Mac ( _) => panic ! ( "Shouldn't exist here" ) ,
2543+ } ;
24692544
2545+ let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( p. id ) ;
24702546 P ( hir:: Pat {
24712547 id : node_id,
24722548 hir_id,
2473- node : match p. node {
2474- PatKind :: Wild => hir:: PatKind :: Wild ,
2475- PatKind :: Ident ( ref binding_mode, pth1, ref sub) => {
2476- match self . resolver . get_resolution ( p. id ) . map ( |d| d. base_def ( ) ) {
2477- // `None` can occur in body-less function signatures
2478- def @ None | def @ Some ( Def :: Local ( _) ) => {
2479- let canonical_id = match def {
2480- Some ( Def :: Local ( id) ) => id,
2481- _ => p. id
2482- } ;
2483- hir:: PatKind :: Binding ( self . lower_binding_mode ( binding_mode) ,
2484- canonical_id,
2485- respan ( pth1. span , pth1. node . name ) ,
2486- sub. as_ref ( ) . map ( |x| self . lower_pat ( x) ) )
2487- }
2488- Some ( def) => {
2489- hir:: PatKind :: Path ( hir:: QPath :: Resolved ( None , P ( hir:: Path {
2490- span : pth1. span ,
2491- def,
2492- segments : hir_vec ! [
2493- hir:: PathSegment :: from_name( pth1. node. name)
2494- ] ,
2495- } ) ) )
2496- }
2497- }
2498- }
2499- PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( P ( self . lower_expr ( e) ) ) ,
2500- PatKind :: TupleStruct ( ref path, ref pats, ddpos) => {
2501- let qpath = self . lower_qpath ( p. id , & None , path, ParamMode :: Optional ,
2502- ImplTraitContext :: Disallowed ) ;
2503- hir:: PatKind :: TupleStruct ( qpath,
2504- pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
2505- ddpos)
2506- }
2507- PatKind :: Path ( ref qself, ref path) => {
2508- hir:: PatKind :: Path ( self . lower_qpath ( p. id , qself, path, ParamMode :: Optional ,
2509- ImplTraitContext :: Disallowed ) )
2510- }
2511- PatKind :: Struct ( ref path, ref fields, etc) => {
2512- let qpath = self . lower_qpath ( p. id , & None , path, ParamMode :: Optional ,
2513- ImplTraitContext :: Disallowed ) ;
2514-
2515- let fs = fields. iter ( )
2516- . map ( |f| {
2517- Spanned {
2518- span : f. span ,
2519- node : hir:: FieldPat {
2520- name : self . lower_ident ( f. node . ident ) ,
2521- pat : self . lower_pat ( & f. node . pat ) ,
2522- is_shorthand : f. node . is_shorthand ,
2523- } ,
2524- }
2525- } )
2526- . collect ( ) ;
2527- hir:: PatKind :: Struct ( qpath, fs, etc)
2528- }
2529- PatKind :: Tuple ( ref elts, ddpos) => {
2530- hir:: PatKind :: Tuple ( elts. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) , ddpos)
2531- }
2532- PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
2533- PatKind :: Ref ( ref inner, mutbl) => {
2534- hir:: PatKind :: Ref ( self . lower_pat ( inner) , self . lower_mutability ( mutbl) )
2535- }
2536- PatKind :: Range ( ref e1, ref e2, ref end) => {
2537- hir:: PatKind :: Range ( P ( self . lower_expr ( e1) ) ,
2538- P ( self . lower_expr ( e2) ) ,
2539- self . lower_range_end ( end) )
2540- }
2541- PatKind :: Slice ( ref before, ref slice, ref after) => {
2542- hir:: PatKind :: Slice ( before. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
2543- slice. as_ref ( ) . map ( |x| self . lower_pat ( x) ) ,
2544- after. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) )
2545- }
2546- PatKind :: Mac ( _) => panic ! ( "Shouldn't exist here" ) ,
2547- } ,
2549+ node,
25482550 span : p. span ,
25492551 } )
25502552 }
0 commit comments