-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Point to closure when emitting 'cannot move out' for captured variable
- Loading branch information
1 parent
c3c0f80
commit 21b7052
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.