-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011
Point to closure when emitting 'cannot move out' for captured variable Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question). cc `@Aaron1011`
- Loading branch information
Showing
13 changed files
with
503 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Regression test for #87456. | ||
|
||
fn take_mut(_val: impl FnMut()) {} | ||
|
||
fn main() { | ||
let val = String::new(); | ||
//~^ NOTE: captured outer variable | ||
take_mut(|| { | ||
//~^ NOTE: captured by this `FnMut` closure | ||
let _foo: String = val; | ||
//~^ ERROR: cannot move out of `val`, a captured variable in an `FnMut` closure [E0507] | ||
//~| NOTE: move occurs because | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure | ||
--> $DIR/issue-87456-point-to-closure.rs:10:28 | ||
| | ||
LL | let val = String::new(); | ||
| --- captured outer variable | ||
LL | | ||
LL | take_mut(|| { | ||
| ______________- | ||
LL | | | ||
LL | | let _foo: String = val; | ||
| | ^^^ | ||
| | | | ||
| | move occurs because `val` has type `String`, which does not implement the `Copy` trait | ||
| | help: consider borrowing here: `&val` | ||
LL | | | ||
LL | | | ||
LL | | }) | ||
| |_____- captured by this `FnMut` closure | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0507`. |
14 changes: 9 additions & 5 deletions
14
src/test/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.