1
1
use crate :: utils:: span_lint;
2
2
use rustc:: hir:: intravisit as visit;
3
- use rustc:: hir:: intravisit:: { walk_expr, NestedVisitorMap , Visitor } ;
4
3
use rustc:: hir:: * ;
5
4
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
6
5
use rustc:: middle:: expr_use_visitor:: * ;
7
6
use rustc:: middle:: mem_categorization:: { cmt_, Categorization } ;
8
7
use rustc:: ty:: layout:: LayoutOf ;
9
- use rustc:: ty:: { self , Ty , UpvarCapture } ;
8
+ use rustc:: ty:: { self , Ty } ;
10
9
use rustc:: util:: nodemap:: NodeSet ;
11
10
use rustc:: { declare_tool_lint, lint_array} ;
12
11
use syntax:: ast:: NodeId ;
@@ -89,17 +88,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
89
88
let region_scope_tree = & cx. tcx . region_scope_tree ( fn_def_id) ;
90
89
ExprUseVisitor :: new ( & mut v, cx. tcx , cx. param_env , region_scope_tree, cx. tables , None ) . consume_body ( body) ;
91
90
92
- let mut capture_visitor = CaptureVisitor {
93
- cx,
94
- moved : NodeSet :: default ( ) ,
95
- } ;
96
- capture_visitor. visit_body ( body) ;
97
-
98
- for node in v. set . difference ( & capture_visitor. moved ) {
91
+ for node in v. set {
99
92
span_lint (
100
93
cx,
101
94
BOXED_LOCAL ,
102
- cx. tcx . hir ( ) . span ( * node) ,
95
+ cx. tcx . hir ( ) . span ( node) ,
103
96
"local variable doesn't need to be boxed here" ,
104
97
) ;
105
98
}
@@ -109,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
109
102
impl < ' a , ' tcx > Delegate < ' tcx > for EscapeDelegate < ' a , ' tcx > {
110
103
fn consume ( & mut self , _: NodeId , _: Span , cmt : & cmt_ < ' tcx > , mode : ConsumeMode ) {
111
104
if let Categorization :: Local ( lid) = cmt. cat {
112
- if let Move ( DirectRefMove ) = mode {
105
+ if let Move ( DirectRefMove ) | Move ( CaptureMove ) = mode {
113
106
// moved out or in. clearly can't be localized
114
107
self . set . remove ( & lid) ;
115
108
}
@@ -199,32 +192,3 @@ impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
199
192
}
200
193
}
201
194
}
202
-
203
- struct CaptureVisitor < ' a , ' tcx : ' a > {
204
- cx : & ' a LateContext < ' a , ' tcx > ,
205
- moved : NodeSet ,
206
- }
207
-
208
- impl < ' a , ' tcx > Visitor < ' tcx > for CaptureVisitor < ' a , ' tcx > {
209
- fn visit_expr ( & mut self , expr : & ' tcx Expr ) {
210
- if let ExprKind :: Closure ( ..) = expr. node {
211
- if let ty:: Closure ( def_id, _) = & self . cx . tables . expr_ty ( expr) . sty {
212
- if let Some ( upvar_list) = & self . cx . tables . upvar_list . get ( & def_id) {
213
- for upvar_id in upvar_list. iter ( ) {
214
- if let UpvarCapture :: ByValue = self . cx . tables . upvar_capture ( * upvar_id) {
215
- let hir_id = upvar_id. var_path . hir_id ;
216
- let id = & self . cx . tcx . hir ( ) . hir_to_node_id ( hir_id) ;
217
- self . moved . insert ( * id) ;
218
- }
219
- }
220
- }
221
- }
222
- } else {
223
- walk_expr ( self , expr) ;
224
- }
225
- }
226
-
227
- fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
228
- NestedVisitorMap :: None
229
- }
230
- }
0 commit comments