forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#65730 - csmoe:return-lifetime, r=nikomatsakis
Suggest to add lifetime constraint at explicit ouput of functions Closes rust-lang#62097
- Loading branch information
Showing
12 changed files
with
103 additions
and
29 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
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,29 @@ | ||
error[E0373]: closure may outlive the current function, but it borrows `self`, which is owned by the current function | ||
--> $DIR/issue-62097.rs:13:13 | ||
| | ||
LL | foo(|| self.bar()).await; | ||
| ^^ ---- `self` is borrowed here | ||
| | | ||
| may outlive borrowed value `self` | ||
| | ||
note: function requires argument type to outlive `'static` | ||
--> $DIR/issue-62097.rs:13:9 | ||
| | ||
LL | foo(|| self.bar()).await; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | foo(move || self.bar()).await; | ||
| ^^^^^^^ | ||
|
||
error[E0521]: borrowed data escapes outside of function | ||
--> $DIR/issue-62097.rs:13:9 | ||
| | ||
LL | pub async fn run_dummy_fn(&self) { | ||
| ----- `self` is a reference that is only valid in the function body | ||
LL | foo(|| self.bar()).await; | ||
| ^^^^^^^^^^^^^^^^^^ `self` escapes the function body here | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0373`. |
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,19 @@ | ||
// edition:2018 | ||
async fn foo<F>(fun: F) | ||
where | ||
F: FnOnce() + 'static | ||
{ | ||
fun() | ||
} | ||
|
||
struct Struct; | ||
|
||
impl Struct { | ||
pub async fn run_dummy_fn(&self) { //~ ERROR cannot infer | ||
foo(|| self.bar()).await; | ||
} | ||
|
||
pub fn bar(&self) {} | ||
} | ||
|
||
fn main() {} |
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,16 @@ | ||
error: cannot infer an appropriate lifetime | ||
--> $DIR/issue-62097.rs:12:31 | ||
| | ||
LL | pub async fn run_dummy_fn(&self) { | ||
| ^^^^^ ...but this borrow... | ||
LL | foo(|| self.bar()).await; | ||
| --- this return type evaluates to the `'static` lifetime... | ||
| | ||
note: ...can't outlive the lifetime `'_` as defined on the method body at 12:31 | ||
--> $DIR/issue-62097.rs:12:31 | ||
| | ||
LL | pub async fn run_dummy_fn(&self) { | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
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