Skip to content

Fix boxed_local suggestion #3794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
if let Categorization::Local(lid) = cmt.cat {
if let Move(DirectRefMove) = mode {
// Moved out or in. Clearly can't be localized.
if let Move(DirectRefMove) | Move(CaptureMove) = mode {
// moved out or in. clearly can't be localized
self.set.remove(&lid);
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/escape_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,23 @@ trait MyTrait {
impl<T> MyTrait for Box<T> {
fn do_sth(self) {}
}

// Issue #3739 - capture in closures
mod issue_3739 {
use super::A;

fn consume<T>(_: T) {}
fn borrow<T>(_: &T) {}

fn closure_consume(x: Box<A>) {
let _ = move || {
consume(x);
};
}

fn closure_borrow(x: Box<A>) {
let _ = || {
borrow(&x);
};
}
}
8 changes: 7 additions & 1 deletion tests/ui/escape_analysis.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ error: local variable doesn't need to be boxed here
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
| ^^^^^^^^^^^

error: aborting due to 2 previous errors
error: local variable doesn't need to be boxed here
--> $DIR/escape_analysis.rs:165:23
|
LL | fn closure_borrow(x: Box<A>) {
| ^

error: aborting due to 3 previous errors