@@ -42,79 +42,42 @@ impl<'hir> Entry<'hir> {
4242
4343fn fn_decl < ' hir > ( node : Node < ' hir > ) -> Option < & ' hir FnDecl < ' hir > > {
4444 match node {
45- Node :: Item ( ref item) => match item. kind {
46- ItemKind :: Fn ( ref sig, _, _) => Some ( & sig. decl ) ,
47- _ => None ,
48- } ,
49-
50- Node :: TraitItem ( ref item) => match item. kind {
51- TraitItemKind :: Fn ( ref sig, _) => Some ( & sig. decl ) ,
52- _ => None ,
53- } ,
54-
55- Node :: ImplItem ( ref item) => match item. kind {
56- ImplItemKind :: Fn ( ref sig, _) => Some ( & sig. decl ) ,
57- _ => None ,
58- } ,
59-
60- Node :: Expr ( ref expr) => match expr. kind {
61- ExprKind :: Closure ( _, ref fn_decl, ..) => Some ( fn_decl) ,
62- _ => None ,
63- } ,
64-
45+ Node :: Item ( Item { kind : ItemKind :: Fn ( sig, _, _) , .. } )
46+ | Node :: TraitItem ( TraitItem { kind : TraitItemKind :: Fn ( sig, _) , .. } )
47+ | Node :: ImplItem ( ImplItem { kind : ImplItemKind :: Fn ( sig, _) , .. } ) => Some ( & sig. decl ) ,
48+ Node :: Expr ( Expr { kind : ExprKind :: Closure ( _, fn_decl, ..) , .. } ) => Some ( fn_decl) ,
6549 _ => None ,
6650 }
6751}
6852
6953fn fn_sig < ' hir > ( node : Node < ' hir > ) -> Option < & ' hir FnSig < ' hir > > {
7054 match & node {
71- Node :: Item ( item) => match & item. kind {
72- ItemKind :: Fn ( sig, _, _) => Some ( sig) ,
73- _ => None ,
74- } ,
75-
76- Node :: TraitItem ( item) => match & item. kind {
77- TraitItemKind :: Fn ( sig, _) => Some ( sig) ,
78- _ => None ,
79- } ,
80-
81- Node :: ImplItem ( item) => match & item. kind {
82- ImplItemKind :: Fn ( sig, _) => Some ( sig) ,
83- _ => None ,
84- } ,
85-
55+ Node :: Item ( Item { kind : ItemKind :: Fn ( sig, _, _) , .. } )
56+ | Node :: TraitItem ( TraitItem { kind : TraitItemKind :: Fn ( sig, _) , .. } )
57+ | Node :: ImplItem ( ImplItem { kind : ImplItemKind :: Fn ( sig, _) , .. } ) => Some ( sig) ,
8658 _ => None ,
8759 }
8860}
8961
9062fn associated_body < ' hir > ( node : Node < ' hir > ) -> Option < BodyId > {
9163 match node {
92- Node :: Item ( item) => match item. kind {
93- ItemKind :: Const ( _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) => {
94- Some ( body)
95- }
96- _ => None ,
97- } ,
98-
99- Node :: TraitItem ( item) => match item. kind {
100- TraitItemKind :: Const ( _, Some ( body) ) | TraitItemKind :: Fn ( _, TraitFn :: Provided ( body) ) => {
101- Some ( body)
102- }
103- _ => None ,
104- } ,
105-
106- Node :: ImplItem ( item) => match item. kind {
107- ImplItemKind :: Const ( _, body) | ImplItemKind :: Fn ( _, body) => Some ( body) ,
108- _ => None ,
109- } ,
64+ Node :: Item ( Item {
65+ kind : ItemKind :: Const ( _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) ,
66+ ..
67+ } )
68+ | Node :: TraitItem ( TraitItem {
69+ kind :
70+ TraitItemKind :: Const ( _, Some ( body) ) | TraitItemKind :: Fn ( _, TraitFn :: Provided ( body) ) ,
71+ ..
72+ } )
73+ | Node :: ImplItem ( ImplItem {
74+ kind : ImplItemKind :: Const ( _, body) | ImplItemKind :: Fn ( _, body) ,
75+ ..
76+ } )
77+ | Node :: Expr ( Expr { kind : ExprKind :: Closure ( .., body, _, _) , .. } ) => Some ( * body) ,
11078
11179 Node :: AnonConst ( constant) => Some ( constant. body ) ,
11280
113- Node :: Expr ( expr) => match expr. kind {
114- ExprKind :: Closure ( .., body, _, _) => Some ( body) ,
115- _ => None ,
116- } ,
117-
11881 _ => None ,
11982 }
12083}
@@ -518,20 +481,21 @@ impl<'hir> Map<'hir> {
518481 }
519482
520483 pub fn get_generics ( & self , id : DefId ) -> Option < & ' hir Generics < ' hir > > {
521- self . get_if_local ( id) . and_then ( |node| match node {
522- Node :: ImplItem ( ref impl_item) => Some ( & impl_item. generics ) ,
523- Node :: TraitItem ( ref trait_item) => Some ( & trait_item. generics ) ,
524- Node :: Item ( ref item) => match item. kind {
525- ItemKind :: Fn ( _, ref generics, _)
526- | ItemKind :: TyAlias ( _, ref generics)
527- | ItemKind :: Enum ( _, ref generics)
528- | ItemKind :: Struct ( _, ref generics)
529- | ItemKind :: Union ( _, ref generics)
530- | ItemKind :: Trait ( _, _, ref generics, ..)
531- | ItemKind :: TraitAlias ( ref generics, _)
532- | ItemKind :: Impl { ref generics, .. } => Some ( generics) ,
533- _ => None ,
534- } ,
484+ self . get_if_local ( id) . and_then ( |node| match & node {
485+ Node :: ImplItem ( impl_item) => Some ( & impl_item. generics ) ,
486+ Node :: TraitItem ( trait_item) => Some ( & trait_item. generics ) ,
487+ Node :: Item ( Item {
488+ kind :
489+ ItemKind :: Fn ( _, generics, _)
490+ | ItemKind :: TyAlias ( _, generics)
491+ | ItemKind :: Enum ( _, generics)
492+ | ItemKind :: Struct ( _, generics)
493+ | ItemKind :: Union ( _, generics)
494+ | ItemKind :: Trait ( _, _, generics, ..)
495+ | ItemKind :: TraitAlias ( generics, _)
496+ | ItemKind :: Impl { generics, .. } ,
497+ ..
498+ } ) => Some ( generics) ,
535499 _ => None ,
536500 } )
537501 }
@@ -571,11 +535,12 @@ impl<'hir> Map<'hir> {
571535 _ => return false ,
572536 }
573537 match self . find ( self . get_parent_node ( id) ) {
574- Some ( Node :: Item ( _) ) | Some ( Node :: TraitItem ( _) ) | Some ( Node :: ImplItem ( _) ) => true ,
575- Some ( Node :: Expr ( e) ) => match e. kind {
576- ExprKind :: Closure ( ..) => true ,
577- _ => false ,
578- } ,
538+ Some (
539+ Node :: Item ( _)
540+ | Node :: TraitItem ( _)
541+ | Node :: ImplItem ( _)
542+ | Node :: Expr ( Expr { kind : ExprKind :: Closure ( ..) , .. } ) ,
543+ ) => true ,
579544 _ => false ,
580545 }
581546 }
@@ -642,12 +607,8 @@ impl<'hir> Map<'hir> {
642607 if let ( Some ( ( _, next_node) ) , false ) = ( iter. peek ( ) , ignore_tail) {
643608 match next_node {
644609 Node :: Block ( Block { expr : None , .. } ) => return None ,
645- Node :: Block ( Block { expr : Some ( expr) , .. } ) => {
646- if hir_id != expr. hir_id {
647- // The current node is not the tail expression of its parent.
648- return None ;
649- }
650- }
610+ // The current node is not the tail expression of its parent.
611+ Node :: Block ( Block { expr : Some ( e) , .. } ) if hir_id != e. hir_id => return None ,
651612 _ => { }
652613 }
653614 }
@@ -657,14 +618,11 @@ impl<'hir> Map<'hir> {
657618 | Node :: TraitItem ( _)
658619 | Node :: Expr ( Expr { kind : ExprKind :: Closure ( ..) , .. } )
659620 | Node :: ImplItem ( _) => return Some ( hir_id) ,
660- Node :: Expr ( ref expr) => {
661- match expr. kind {
662- // Ignore `return`s on the first iteration
663- ExprKind :: Loop ( ..) | ExprKind :: Ret ( ..) => return None ,
664- _ => { }
665- }
621+ // Ignore `return`s on the first iteration
622+ Node :: Expr ( Expr { kind : ExprKind :: Loop ( ..) | ExprKind :: Ret ( ..) , .. } )
623+ | Node :: Local ( _) => {
624+ return None ;
666625 }
667- Node :: Local ( _) => return None ,
668626 _ => { }
669627 }
670628 }
@@ -708,17 +666,12 @@ impl<'hir> Map<'hir> {
708666 pub fn get_match_if_cause ( & self , hir_id : HirId ) -> Option < & ' hir Expr < ' hir > > {
709667 for ( _, node) in self . parent_iter ( hir_id) {
710668 match node {
711- Node :: Item ( _) | Node :: ForeignItem ( _) | Node :: TraitItem ( _) | Node :: ImplItem ( _) => {
712- break ;
713- }
714- Node :: Expr ( expr) => match expr. kind {
715- ExprKind :: Match ( _, _, _) => return Some ( expr) ,
716- _ => { }
717- } ,
718- Node :: Stmt ( stmt) => match stmt. kind {
719- StmtKind :: Local ( _) => break ,
720- _ => { }
721- } ,
669+ Node :: Item ( _)
670+ | Node :: ForeignItem ( _)
671+ | Node :: TraitItem ( _)
672+ | Node :: ImplItem ( _)
673+ | Node :: Stmt ( Stmt { kind : StmtKind :: Local ( _) , .. } ) => break ,
674+ Node :: Expr ( expr @ Expr { kind : ExprKind :: Match ( ..) , .. } ) => return Some ( expr) ,
722675 _ => { }
723676 }
724677 }
@@ -728,32 +681,22 @@ impl<'hir> Map<'hir> {
728681 /// Returns the nearest enclosing scope. A scope is roughly an item or block.
729682 pub fn get_enclosing_scope ( & self , hir_id : HirId ) -> Option < HirId > {
730683 for ( hir_id, node) in self . parent_iter ( hir_id) {
731- if match node {
732- Node :: Item ( i ) => match i . kind {
684+ if let Node :: Item ( Item {
685+ kind :
733686 ItemKind :: Fn ( ..)
734687 | ItemKind :: Mod ( ..)
735688 | ItemKind :: Enum ( ..)
736689 | ItemKind :: Struct ( ..)
737690 | ItemKind :: Union ( ..)
738691 | ItemKind :: Trait ( ..)
739- | ItemKind :: Impl { .. } => true ,
740- _ => false ,
741- } ,
742- Node :: ForeignItem ( fi) => match fi. kind {
743- ForeignItemKind :: Fn ( ..) => true ,
744- _ => false ,
745- } ,
746- Node :: TraitItem ( ti) => match ti. kind {
747- TraitItemKind :: Fn ( ..) => true ,
748- _ => false ,
749- } ,
750- Node :: ImplItem ( ii) => match ii. kind {
751- ImplItemKind :: Fn ( ..) => true ,
752- _ => false ,
753- } ,
754- Node :: Block ( _) => true ,
755- _ => false ,
756- } {
692+ | ItemKind :: Impl { .. } ,
693+ ..
694+ } )
695+ | Node :: ForeignItem ( ForeignItem { kind : ForeignItemKind :: Fn ( ..) , .. } )
696+ | Node :: TraitItem ( TraitItem { kind : TraitItemKind :: Fn ( ..) , .. } )
697+ | Node :: ImplItem ( ImplItem { kind : ImplItemKind :: Fn ( ..) , .. } )
698+ | Node :: Block ( _) = node
699+ {
757700 return Some ( hir_id) ;
758701 }
759702 }
@@ -769,11 +712,11 @@ impl<'hir> Map<'hir> {
769712 return CRATE_HIR_ID ;
770713 }
771714 match self . get ( scope) {
772- Node :: Item ( i ) => match i . kind {
773- ItemKind :: OpaqueTy ( OpaqueTy { impl_trait_fn : None , .. } ) => { }
774- _ => break ,
775- } ,
776- Node :: Block ( _) => { }
715+ Node :: Item ( Item {
716+ kind : ItemKind :: OpaqueTy ( OpaqueTy { impl_trait_fn : None , .. } ) ,
717+ ..
718+ } )
719+ | Node :: Block ( _) => { }
777720 _ => break ,
778721 }
779722 }
@@ -821,14 +764,11 @@ impl<'hir> Map<'hir> {
821764
822765 pub fn expect_variant_data ( & self , id : HirId ) -> & ' hir VariantData < ' hir > {
823766 match self . find ( id) {
824- Some ( Node :: Item ( i) ) => match i. kind {
825- ItemKind :: Struct ( ref struct_def, _) | ItemKind :: Union ( ref struct_def, _) => {
826- struct_def
827- }
828- _ => bug ! ( "struct ID bound to non-struct {}" , self . node_to_string( id) ) ,
829- } ,
767+ Some (
768+ Node :: Ctor ( vd)
769+ | Node :: Item ( Item { kind : ItemKind :: Struct ( vd, _) | ItemKind :: Union ( vd, _) , .. } ) ,
770+ ) => vd,
830771 Some ( Node :: Variant ( variant) ) => & variant. data ,
831- Some ( Node :: Ctor ( data) ) => data,
832772 _ => bug ! ( "expected struct or variant, found {}" , self . node_to_string( id) ) ,
833773 }
834774 }
0 commit comments