Skip to content

Commit 5e83ddd

Browse files
author
Lukas Markeffsky
committed
don't suggest move for borrows that aren't closures
1 parent 5bd28f5 commit 5e83ddd

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1730,18 +1730,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17301730
(
17311731
Some(name),
17321732
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
1733-
) => self.report_escaping_closure_capture(
1734-
borrow_spans,
1735-
borrow_span,
1736-
&RegionName {
1737-
name: self.synthesize_region_name(),
1738-
source: RegionNameSource::Static,
1739-
},
1740-
ConstraintCategory::CallArgument(None),
1741-
var_or_use_span,
1742-
&format!("`{}`", name),
1743-
"block",
1744-
),
1733+
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
1734+
.report_escaping_closure_capture(
1735+
borrow_spans,
1736+
borrow_span,
1737+
&RegionName {
1738+
name: self.synthesize_region_name(),
1739+
source: RegionNameSource::Static,
1740+
},
1741+
ConstraintCategory::CallArgument(None),
1742+
var_or_use_span,
1743+
&format!("`{}`", name),
1744+
"block",
1745+
),
17451746
(
17461747
Some(name),
17471748
BorrowExplanation::MustBeValidFor {
@@ -1754,7 +1755,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17541755
span,
17551756
..
17561757
},
1757-
) if borrow_spans.for_generator() | borrow_spans.for_closure() => self
1758+
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
17581759
.report_escaping_closure_capture(
17591760
borrow_spans,
17601761
borrow_span,

tests/ui/closures/issue-113087.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn some_fn<'a>(_: &'a i32, _: impl FnOnce(&'a i32)) {}
2+
3+
fn main() {
4+
let some_closure = |_| {};
5+
6+
for a in [1] {
7+
some_fn(&a, |c| { //~ ERROR does not live long enough
8+
some_closure(c);
9+
});
10+
}
11+
}

tests/ui/closures/issue-113087.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0597]: `a` does not live long enough
2+
--> $DIR/issue-113087.rs:7:17
3+
|
4+
LL | for a in [1] {
5+
| - binding `a` declared here
6+
LL | some_fn(&a, |c| {
7+
| ^^ borrowed value does not live long enough
8+
LL | some_closure(c);
9+
| ------------ borrow later captured here by closure
10+
LL | });
11+
LL | }
12+
| - `a` dropped here while still borrowed
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)