Skip to content
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

don't suggest move for borrows that aren't closures #113137

Merged
merged 1 commit into from
Jun 29, 2023
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
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`.