Skip to content

Commit b7d4735

Browse files
committed
Merge consume and consume_pat in escape analysis
FIXME: This doesn't work and probably needs a rewrite of the lint See #4628 (comment)
1 parent c420b07 commit b7d4735

File tree

2 files changed

+11
-67
lines changed

2 files changed

+11
-67
lines changed

clippy_lints/src/escape.rs

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -120,44 +120,27 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
120120
self.set.remove(&lid);
121121
}
122122
}
123-
}
124-
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
125123
let map = &self.cx.tcx.hir();
126-
if is_argument(map, consume_pat.hir_id) {
124+
if is_argument(map, cmt.hir_id) {
127125
// Skip closure arguments
128-
let parent_id = map.get_parent_node(consume_pat.hir_id);
126+
let parent_id = map.get_parent_node(cmt.hir_id);
129127
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) {
130128
return;
131129
}
132130

133131
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
134-
self.set.insert(consume_pat.hir_id);
132+
self.set.insert(cmt.hir_id);
135133
}
136134
return;
137135
}
138-
if let Categorization::Rvalue = cmt.cat {
139-
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(cmt.hir_id)) {
140-
if let StmtKind::Local(ref loc) = st.kind {
141-
if let Some(ref ex) = loc.init {
142-
if let ExprKind::Box(..) = ex.kind {
143-
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
144-
// let x = box (...)
145-
self.set.insert(consume_pat.hir_id);
146-
}
147-
// TODO Box::new
148-
// TODO vec![]
149-
// TODO "foo".to_owned() and friends
150-
}
151-
}
152-
}
153-
}
154-
}
155136
if let Categorization::Local(lid) = cmt.cat {
156-
if self.set.contains(&lid) {
157-
// let y = x where x is known
158-
// remove x, insert y
159-
self.set.insert(consume_pat.hir_id);
160-
self.set.remove(&lid);
137+
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
138+
if self.set.contains(&lid) {
139+
// let y = x where x is known
140+
// remove x, insert y
141+
self.set.insert(cmt.hir_id);
142+
self.set.remove(&lid);
143+
}
161144
}
162145
}
163146
}
@@ -166,26 +149,9 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
166149
&mut self,
167150
cmt: &cmt_<'tcx>,
168151
_: ty::BorrowKind,
169-
loan_cause: LoanCause,
170152
) {
171153
if let Categorization::Local(lid) = cmt.cat {
172-
match loan_cause {
173-
// `x.foo()`
174-
// Used without autoderef-ing (i.e., `x.clone()`).
175-
LoanCause::AutoRef |
176-
177-
// `&x`
178-
// `foo(&x)` where no extra autoref-ing is happening.
179-
LoanCause::AddrOf |
180-
181-
// `match x` can move.
182-
LoanCause::MatchDiscriminant => {
183-
self.set.remove(&lid);
184-
}
185-
186-
// Do nothing for matches, etc. These can't escape.
187-
_ => {}
188-
}
154+
self.set.remove(&lid);
189155
}
190156
}
191157

tests/ui/escape_analysis.stderr

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
error: local variable doesn't need to be boxed here
2-
--> $DIR/escape_analysis.rs:39:13
3-
|
4-
LL | fn warn_arg(x: Box<A>) {
5-
| ^
6-
|
7-
= note: `-D clippy::boxed-local` implied by `-D warnings`
8-
9-
error: local variable doesn't need to be boxed here
10-
--> $DIR/escape_analysis.rs:130:12
11-
|
12-
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
13-
| ^^^^^^^^^^^
14-
15-
error: local variable doesn't need to be boxed here
16-
--> $DIR/escape_analysis.rs:170:23
17-
|
18-
LL | fn closure_borrow(x: Box<A>) {
19-
| ^
20-
21-
error: aborting due to 3 previous errors
22-

0 commit comments

Comments
 (0)