1
1
use rustc:: hir:: intravisit as visit;
2
- use rustc:: hir:: * ;
2
+ use rustc:: hir:: { self , * } ;
3
3
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
4
4
use rustc:: middle:: expr_use_visitor:: * ;
5
5
use rustc:: middle:: mem_categorization:: { cmt_, Categorization } ;
@@ -101,6 +101,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
101
101
}
102
102
}
103
103
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
+
104
117
impl < ' a , ' tcx > Delegate < ' tcx > for EscapeDelegate < ' a , ' tcx > {
105
118
fn consume ( & mut self , _: HirId , _: Span , cmt : & cmt_ < ' tcx > , mode : ConsumeMode ) {
106
119
if let Categorization :: Local ( lid) = cmt. cat {
@@ -113,11 +126,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
113
126
fn matched_pat ( & mut self , _: & Pat , _: & cmt_ < ' tcx > , _: MatchMode ) { }
114
127
fn consume_pat ( & mut self , consume_pat : & Pat , cmt : & cmt_ < ' tcx > , _: ConsumeMode ) {
115
128
let map = & self . cx . tcx . hir ( ) ;
116
- if map . is_argument ( consume_pat. hir_id ) {
129
+ if is_argument ( map , consume_pat. hir_id ) {
117
130
// 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) ) {
119
133
return ;
120
134
}
135
+
121
136
if is_non_trait_box ( cmt. ty ) && !self . is_large_box ( cmt. ty ) {
122
137
self . set . insert ( consume_pat. hir_id ) ;
123
138
}
0 commit comments