Skip to content

Commit

Permalink
Adapt tests from rust-lang#105258
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 30, 2023
1 parent 473c88d commit 8ad5ea7
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 6 deletions.
52 changes: 49 additions & 3 deletions tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:17:47
--> $DIR/signature-mismatch.rs:36:47
|
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:11:40
--> $DIR/signature-mismatch.rs:17:40
|
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`

error: aborting due to previous error
error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:41:57
|
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:18:57
|
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`

error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:49:10
|
LL | fn async_fn_multiple<'a, 'b>(
| -- this lifetime was captured
...
LL | ) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:20:12
|
LL | -> impl Future<Output = Vec<u8>> + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + Captures2<'a, 'b>`

error[E0309]: the parameter type `T` may not live long enough
--> $DIR/signature-mismatch.rs:58:10
|
LL | ) -> impl Future<Output = Vec<u8>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future<Output = Vec<u8>>` will meet its required lifetime bounds...
|
note: ...that is required by this bound
--> $DIR/signature-mismatch.rs:25:42
|
LL | ) -> impl Future<Output = Vec<u8>> + 'a;
| ^^
help: consider adding an explicit lifetime bound...
|
LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>(
| ++++

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0309`.
52 changes: 49 additions & 3 deletions tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:17:47
--> $DIR/signature-mismatch.rs:36:47
|
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:11:40
--> $DIR/signature-mismatch.rs:17:40
|
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`

error: aborting due to previous error
error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:41:57
|
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:18:57
|
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a`

error: return type captures more lifetimes than trait definition
--> $DIR/signature-mismatch.rs:49:10
|
LL | fn async_fn_multiple<'a, 'b>(
| -- this lifetime was captured
...
LL | ) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/signature-mismatch.rs:20:12
|
LL | -> impl Future<Output = Vec<u8>> + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + Captures2<'a, 'b>`

error[E0309]: the parameter type `T` may not live long enough
--> $DIR/signature-mismatch.rs:58:10
|
LL | ) -> impl Future<Output = Vec<u8>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future<Output = Vec<u8>>` will meet its required lifetime bounds...
|
note: ...that is required by this bound
--> $DIR/signature-mismatch.rs:25:42
|
LL | ) -> impl Future<Output = Vec<u8>> + 'a;
| ^^
help: consider adding an explicit lifetime bound...
|
LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>(
| ++++

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0309`.
53 changes: 53 additions & 0 deletions tests/ui/impl-trait/in-trait/signature-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@

use std::future::Future;

trait Captures<'a> {}
impl<T> Captures<'_> for T {}

trait Captures2<'a, 'b> {}
impl<T> Captures2<'_, '_> for T {}

pub trait AsyncTrait {
fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>;
fn async_fn_multiple<'a>(&'a self, buff: &[u8])
-> impl Future<Output = Vec<u8>> + Captures<'a>;
fn async_fn_reduce_outlive<'a, T>(
&'a self,
buff: &[u8],
t: T,
) -> impl Future<Output = Vec<u8>> + 'a;
fn async_fn_reduce<'a, T>(
&'a self,
buff: &[u8],
t: T,
) -> impl Future<Output = Vec<u8>> + Captures<'a>;
}

pub struct Struct;
Expand All @@ -18,6 +37,40 @@ impl AsyncTrait for Struct {
//~^ ERROR return type captures more lifetimes than trait definition
async move { buff.to_vec() }
}

fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
//~^ ERROR return type captures more lifetimes than trait definition
async move { buff.to_vec() }
}

fn async_fn_multiple<'a, 'b>(
&'a self,
buff: &'b [u8],
) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> {
//~^ ERROR return type captures more lifetimes than trait definition
async move { buff.to_vec() }
}

fn async_fn_reduce_outlive<'a, 'b, T>(
&'a self,
buff: &'b [u8],
t: T,
) -> impl Future<Output = Vec<u8>> {
//~^ ERROR the parameter type `T` may not live long enough
async move {
let _t = t;
vec![]
}
}

// OK: We remove the `Captures<'a>`, providing a guarantee that we don't capture `'a`,
// but we still fulfill the `Captures<'a>` trait bound.
fn async_fn_reduce<'a, 'b, T>(&'a self, buff: &'b [u8], t: T) -> impl Future<Output = Vec<u8>> {
async move {
let _t = t;
vec![]
}
}
}

fn main() {}

0 comments on commit 8ad5ea7

Please sign in to comment.