Skip to content

Commit

Permalink
Rollup merge of #113137 - lukas-code:no-moving-references, r=compiler…
Browse files Browse the repository at this point in the history
…-errors

don't suggest `move` for borrows that aren't closures

fixes #113087
  • Loading branch information
matthiaskrgr authored Jun 29, 2023
2 parents f35f213 + 5e83ddd commit 7e1869f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
27 changes: 14 additions & 13 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,18 +1730,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(
Some(name),
BorrowExplanation::UsedLater(LaterUseKind::ClosureCapture, var_or_use_span, _),
) => self.report_escaping_closure_capture(
borrow_spans,
borrow_span,
&RegionName {
name: self.synthesize_region_name(),
source: RegionNameSource::Static,
},
ConstraintCategory::CallArgument(None),
var_or_use_span,
&format!("`{}`", name),
"block",
),
) if borrow_spans.for_generator() || borrow_spans.for_closure() => self
.report_escaping_closure_capture(
borrow_spans,
borrow_span,
&RegionName {
name: self.synthesize_region_name(),
source: RegionNameSource::Static,
},
ConstraintCategory::CallArgument(None),
var_or_use_span,
&format!("`{}`", name),
"block",
),
(
Some(name),
BorrowExplanation::MustBeValidFor {
Expand All @@ -1754,7 +1755,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
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(
borrow_spans,
borrow_span,
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/closures/issue-113087.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions tests/ui/closures/issue-113087.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 7e1869f

Please sign in to comment.