-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest move for closures and async blocks in more cases.
- Loading branch information
Showing
9 changed files
with
80 additions
and
64 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
10 changes: 8 additions & 2 deletions
10
src/test/ui/async-await/async-borrowck-escaping-block-error.fixed
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
fn foo() -> Box<impl std::future::Future<Output = u32>> { | ||
fn test_boxed() -> Box<impl std::future::Future<Output = u32>> { | ||
let x = 0u32; | ||
Box::new(async move { x } ) | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn test_ref(x: &u32) -> impl std::future::Future<Output = u32> + '_ { | ||
async move { *x } | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn main() { | ||
let _foo = foo(); | ||
let _ = test_boxed(); | ||
let _ = test_ref(&0u32); | ||
} |
10 changes: 8 additions & 2 deletions
10
src/test/ui/async-await/async-borrowck-escaping-block-error.rs
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
fn foo() -> Box<impl std::future::Future<Output = u32>> { | ||
fn test_boxed() -> Box<impl std::future::Future<Output = u32>> { | ||
let x = 0u32; | ||
Box::new(async { x } ) | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn test_ref(x: &u32) -> impl std::future::Future<Output = u32> + '_ { | ||
async { *x } | ||
//~^ ERROR E0373 | ||
} | ||
|
||
fn main() { | ||
let _foo = foo(); | ||
let _ = test_boxed(); | ||
let _ = test_ref(&0u32); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/test/ui/async-await/async-borrowck-escaping-closure-error.rs
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
error[E0597]: `prefix` does not live long enough | ||
--> $DIR/does-not-live-long-enough.rs:6:51 | ||
error[E0373]: closure may outlive the current function, but it borrows `prefix`, which is owned by the current function | ||
--> $DIR/does-not-live-long-enough.rs:6:33 | ||
| | ||
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> { | ||
| -- lifetime `'a` defined here --------------------------- opaque type requires that `prefix` is borrowed for `'a` | ||
LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) | ||
| --- ^^^^^^ borrowed value does not live long enough | ||
| ^^^ ------ `prefix` is borrowed here | ||
| | | ||
| value captured here | ||
LL | | ||
LL | } | ||
| - `prefix` dropped here while still borrowed | ||
| may outlive borrowed value `prefix` | ||
| | ||
note: closure is returned here | ||
--> $DIR/does-not-live-long-enough.rs:5:55 | ||
| | ||
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` | ||
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: to force the closure to take ownership of `prefix` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> + 'a { | ||
| ^^^^ | ||
LL | self.data.iter().filter(move |s| s.starts_with(prefix)).map(|s| s.as_ref()) | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. | ||
For more information about this error, try `rustc --explain E0373`. |