-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async fn
lifetime elision tests
#63383
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43a2cbd
lifetime elision: add conforming-to-fn tests.
Centril a694782
lifetime elision: add non-conforming-to-fn tests.
Centril d9294a2
lifetime elision: document conformance of 'async fn' to 'fn'.
Centril f395787
Add async version of self_lifetime.rs test.
Centril 5ce8f7a
Add async versions of arbitrary_self_types_pin_lifetime tests.
Centril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/test/ui/self/arbitrary_self_types_pin_lifetime-async.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
async fn pin_ref(self: Pin<&Self>) -> Pin<&Self> { self } | ||
|
||
async fn pin_mut(self: Pin<&mut Self>) -> Pin<&mut Self> { self } | ||
|
||
async fn pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> Pin<Pin<Pin<&Self>>> { self } | ||
|
||
async fn pin_ref_impl_trait(self: Pin<&Self>) -> impl Clone + '_ { self } | ||
|
||
fn b(self: Pin<&Foo>, f: &Foo) -> Pin<&Foo> { self } | ||
} | ||
|
||
type Alias<T> = Pin<T>; | ||
impl Foo { | ||
async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> Alias<&Self> { self } | ||
} | ||
|
||
// FIXME(Centril): extend with the rest of the non-`async fn` test | ||
// when we allow `async fn`s inside traits and trait implementations. | ||
|
||
fn main() { | ||
let mut foo = Foo; | ||
{ Pin::new(&foo).pin_ref() }; | ||
{ Pin::new(&mut foo).pin_mut() }; | ||
{ Pin::new(Pin::new(Pin::new(&foo))).pin_pin_pin_ref() }; | ||
{ Pin::new(&foo).pin_ref_impl_trait() }; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10:48 | ||
| | ||
LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | ||
| - ^^^^^^^^ returning this value requires that `'_` must outlive `'static` | ||
| | | ||
| lifetime `'_` defined here | ||
help: to allow this `impl Trait` to capture borrowed data with lifetime `'_`, add `'_` as a constraint | ||
| | ||
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
16 changes: 16 additions & 0 deletions
16
src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
async fn f(self: Pin<&Self>) -> impl Clone { self } | ||
//~^ ERROR cannot infer an appropriate lifetime | ||
} | ||
|
||
fn main() { | ||
{ Pin::new(&Foo).f() }; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: cannot infer an appropriate lifetime | ||
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10:16 | ||
| | ||
LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | ||
| ^^^^ ---------- this return type evaluates to the `'static` lifetime... | ||
| | | ||
| ...but this borrow... | ||
| | ||
note: ...can't outlive the lifetime '_ as defined on the method body at 10:26 | ||
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10: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 10:26 | ||
| | ||
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
27 changes: 27 additions & 0 deletions
27
src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:45 | ||
| | ||
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:60 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:67 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
28 changes: 28 additions & 0 deletions
28
src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ||
//~^ ERROR missing lifetime specifier | ||
//~| ERROR cannot infer an appropriate lifetime | ||
// FIXME: should be E0623? | ||
|
||
async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
//~^ ERROR missing lifetime specifier | ||
//~| ERROR cannot infer an appropriate lifetime | ||
//~| ERROR missing lifetime specifier | ||
//~| ERROR cannot infer an appropriate lifetime | ||
// FIXME: should be E0623? | ||
} | ||
|
||
type Alias<T> = Pin<T>; | ||
impl Foo { | ||
async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } //~ ERROR E0623 | ||
} | ||
|
||
fn main() {} |
88 changes: 88 additions & 0 deletions
88
src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:45 | ||
| | ||
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:60 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:67 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
| | ||
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple. | ||
|
||
error: cannot infer an appropriate lifetime | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:33 | ||
| | ||
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ||
| ^ ---- this return type evaluates to the `'static` lifetime... | ||
| | | ||
| ...but this borrow... | ||
| | ||
note: ...can't outlive the lifetime '_ as defined on the method body at 10:26 | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:26 | ||
| | ||
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f } | ||
| ^ | ||
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 10:26 | ||
| | ||
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo + '_ { f } | ||
| ^^^^^^^^^ | ||
|
||
error: cannot infer an appropriate lifetime | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:16 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^^^^ ...but this borrow... ----------------- this return type evaluates to the `'static` lifetime... | ||
| | ||
note: ...can't outlive the lifetime '_ as defined on the method body at 15:26 | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:26 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
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 15:26 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) + '_ { (self, f) } | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: cannot infer an appropriate lifetime | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:34 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ ----------------- this return type evaluates to the `'static` lifetime... | ||
| | | ||
| ...but this borrow... | ||
| | ||
note: ...can't outlive the lifetime '_ as defined on the method body at 15:26 | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:26 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) } | ||
| ^ | ||
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 15:26 | ||
| | ||
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) + '_ { (self, f) } | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0623]: lifetime mismatch | ||
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:25:58 | ||
| | ||
LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } | ||
| ----- ^^^ | ||
| | | | ||
| | ...but data from `arg` is returned here | ||
| this parameter and the return type are declared with different lifetimes... | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
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,39 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
#![feature(arbitrary_self_types)] | ||
#![allow(non_snake_case)] | ||
|
||
use std::rc::Rc; | ||
|
||
struct Struct { } | ||
|
||
type Alias = Struct; | ||
|
||
impl Struct { | ||
// Test using an alias for `Struct`: | ||
|
||
async fn alias(self: Alias, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_Alias(self: Box<Alias>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn rc_Alias(self: Rc<Alias>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_box_Alias(self: Box<Box<Alias>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_rc_Alias(self: Box<Rc<Alias>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
} | ||
|
||
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,43 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
#![feature(arbitrary_self_types)] | ||
#![allow(non_snake_case)] | ||
|
||
use std::rc::Rc; | ||
|
||
trait Trait { | ||
type AssocType; | ||
} | ||
|
||
struct Struct { } | ||
|
||
impl Trait for Struct { | ||
type AssocType = Self; | ||
} | ||
|
||
impl Struct { | ||
async fn assoc(self: <Struct as Trait>::AssocType, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_AssocType(self: Box<<Struct as Trait>::AssocType>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn rc_AssocType(self: Rc<<Struct as Trait>::AssocType>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_box_AssocType(self: Box<Box<<Struct as Trait>::AssocType>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn box_rc_AssocType(self: Box<Rc<<Struct as Trait>::AssocType>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
} | ||
|
||
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,41 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
#![feature(arbitrary_self_types)] | ||
#![allow(non_snake_case)] | ||
|
||
use std::rc::Rc; | ||
|
||
struct Struct<'a> { x: &'a u32 } | ||
|
||
type Alias<'a> = Struct<'a>; | ||
|
||
impl<'a> Alias<'a> { | ||
async fn take_self(self, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn take_Alias(self: Alias<'a>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn take_Box_Alias(self: Box<Alias<'a>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn take_Box_Box_Alias(self: Box<Box<Alias<'a>>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn take_Rc_Alias(self: Rc<Alias<'a>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
|
||
async fn take_Box_Rc_Alias(self: Box<Rc<Alias<'a>>>, f: &u32) -> &u32 { | ||
f | ||
} | ||
} | ||
|
||
fn main() { } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.B. these cases where things diverge.
While writing these tests I also hit:
which passes if you remove
async
but with it you get:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this seems like a bug, but I see you filed one already (#63388)