don't suggest move
for borrows that aren't closures
This commit is contained in:
parent
5bd28f5eac
commit
5e83ddd279
3 changed files with 41 additions and 13 deletions
|
@ -1730,7 +1730,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
(
|
(
|
||||||
Some(name),
|
Some(name),
|
||||||
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
|
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
|
||||||
) => self.report_escaping_closure_capture(
|
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
|
||||||
|
.report_escaping_closure_capture(
|
||||||
borrow_spans,
|
borrow_spans,
|
||||||
borrow_span,
|
borrow_span,
|
||||||
&RegionName {
|
&RegionName {
|
||||||
|
@ -1754,7 +1755,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span,
|
span,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
) if borrow_spans.for_generator() | borrow_spans.for_closure() => self
|
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
|
||||||
.report_escaping_closure_capture(
|
.report_escaping_closure_capture(
|
||||||
borrow_spans,
|
borrow_spans,
|
||||||
borrow_span,
|
borrow_span,
|
||||||
|
|
11
tests/ui/closures/issue-113087.rs
Normal file
11
tests/ui/closures/issue-113087.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fn some_fn<'a>(_: &'a i32, _: impl FnOnce(&'a i32)) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let some_closure = |_| {};
|
||||||
|
|
||||||
|
for a in [1] {
|
||||||
|
some_fn(&a, |c| { //~ ERROR does not live long enough
|
||||||
|
some_closure(c);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
16
tests/ui/closures/issue-113087.stderr
Normal file
16
tests/ui/closures/issue-113087.stderr
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
error[E0597]: `a` does not live long enough
|
||||||
|
--> $DIR/issue-113087.rs:7:17
|
||||||
|
|
|
||||||
|
LL | for a in [1] {
|
||||||
|
| - binding `a` declared here
|
||||||
|
LL | some_fn(&a, |c| {
|
||||||
|
| ^^ borrowed value does not live long enough
|
||||||
|
LL | some_closure(c);
|
||||||
|
| ------------ borrow later captured here by closure
|
||||||
|
LL | });
|
||||||
|
LL | }
|
||||||
|
| - `a` dropped here while still borrowed
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0597`.
|
Loading…
Add table
Reference in a new issue