diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-21 15:29:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-21 15:29:02 +0100 |
| commit | e4a634189e3ef7461a40e357633bdbc98cedf5ad (patch) | |
| tree | 3916d5aff87711cd1566c067d259190dbe70b1cb /src/test/ui | |
| parent | 0828d5327b9950ef4b1fedd058bbc8eaed00f8be (diff) | |
| parent | 9124f7a096007b5f96300e61e8f5817df10b315a (diff) | |
| download | rust-e4a634189e3ef7461a40e357633bdbc98cedf5ad.tar.gz rust-e4a634189e3ef7461a40e357633bdbc98cedf5ad.zip | |
Rollup merge of #65730 - csmoe:return-lifetime, r=nikomatsakis
Suggest to add lifetime constraint at explicit ouput of functions Closes #62097
Diffstat (limited to 'src/test/ui')
5 files changed, 64 insertions, 8 deletions
diff --git a/src/test/ui/async-await/issues/issue-62097.nll.stderr b/src/test/ui/async-await/issues/issue-62097.nll.stderr new file mode 100644 index 00000000000..0c64f90cb9f --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.nll.stderr @@ -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`. diff --git a/src/test/ui/async-await/issues/issue-62097.rs b/src/test/ui/async-await/issues/issue-62097.rs new file mode 100644 index 00000000000..ea482d3667e --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.rs @@ -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() {} diff --git a/src/test/ui/async-await/issues/issue-62097.stderr b/src/test/ui/async-await/issues/issue-62097.stderr new file mode 100644 index 00000000000..94afccc06a9 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.stderr @@ -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 + diff --git a/src/test/ui/async-await/issues/issue-63388-2.stderr b/src/test/ui/async-await/issues/issue-63388-2.stderr index efec160588f..7e45d588c6c 100644 --- a/src/test/ui/async-await/issues/issue-63388-2.stderr +++ b/src/test/ui/async-await/issues/issue-63388-2.stderr @@ -20,10 +20,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 11:14 | LL | foo: &dyn Foo, bar: &'a dyn Foo | ^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 11:14 - | -LL | foo + '_ - | error: aborting due to 2 previous errors diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr index bce1900ca60..91075ffbdb6 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr @@ -11,10 +11,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 8:26 | LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | ^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 8:26 - | -LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ^^^^^^^^^^^^^^^ error: aborting due to previous error |
