11use rustc:: hir:: intravisit as visit;
2- use rustc:: hir:: * ;
2+ use rustc:: hir:: { self , * } ;
33use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
44use rustc:: middle:: expr_use_visitor:: * ;
55use rustc:: middle:: mem_categorization:: { cmt_, Categorization } ;
@@ -101,6 +101,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
101101 }
102102}
103103
104+ // TODO: Replace with Map::is_argument(..) when it's fixed
105+ fn is_argument ( map : & hir:: map:: Map < ' _ > , id : HirId ) -> bool {
106+ match map. find ( id) {
107+ Some ( Node :: Binding ( _) ) => ( ) ,
108+ _ => return false ,
109+ }
110+
111+ match map. find ( map. get_parent_node ( id) ) {
112+ Some ( Node :: Arg ( _) ) => true ,
113+ _ => false ,
114+ }
115+ }
116+
104117impl < ' a , ' tcx > Delegate < ' tcx > for EscapeDelegate < ' a , ' tcx > {
105118 fn consume ( & mut self , _: HirId , _: Span , cmt : & cmt_ < ' tcx > , mode : ConsumeMode ) {
106119 if let Categorization :: Local ( lid) = cmt. cat {
@@ -113,11 +126,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
113126 fn matched_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: MatchMode ) { }
114127 fn consume_pat ( & mut self , consume_pat : & Pat , cmt : & cmt_ < ' tcx > , _: ConsumeMode ) {
115128 let map = & self . cx . tcx . hir ( ) ;
116- if map . is_argument ( consume_pat. hir_id ) {
129+ if is_argument ( map , consume_pat. hir_id ) {
117130 // Skip closure arguments
118- if let Some ( Node :: Expr ( ..) ) = map. find ( map. get_parent_node ( consume_pat. hir_id ) ) {
131+ let parent_id = map. get_parent_node ( consume_pat. hir_id ) ;
132+ if let Some ( Node :: Expr ( ..) ) = map. find ( map. get_parent_node ( parent_id) ) {
119133 return ;
120134 }
135+
121136 if is_non_trait_box ( cmt. ty ) && !self . is_large_box ( cmt. ty ) {
122137 self . set . insert ( consume_pat. hir_id ) ;
123138 }
0 commit comments