From 8ad5ea7b0190256cd7d7c9d8f3f614ecb14796ad Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 30 Jun 2023 00:38:34 +0000 Subject: [PATCH] Adapt tests from #105258 --- .../signature-mismatch.current.stderr | 52 ++++++++++++++++-- .../in-trait/signature-mismatch.next.stderr | 52 ++++++++++++++++-- .../impl-trait/in-trait/signature-mismatch.rs | 53 +++++++++++++++++++ 3 files changed, 151 insertions(+), 6 deletions(-) diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr b/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr index 0d805383da144..8c9dd403174b7 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr @@ -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> + '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>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: hidden type inferred to be `impl Future> + '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> + '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>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + '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> + Captures2<'a, 'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type must only reference lifetimes captured by this impl trait + --> $DIR/signature-mismatch.rs:20:12 + | +LL | -> impl Future> + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + Captures2<'a, 'b>` + +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/signature-mismatch.rs:58:10 + | +LL | ) -> impl Future> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future>` will meet its required lifetime bounds... + | +note: ...that is required by this bound + --> $DIR/signature-mismatch.rs:25:42 + | +LL | ) -> impl Future> + '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`. diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr b/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr index 0d805383da144..8c9dd403174b7 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr @@ -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> + '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>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: hidden type inferred to be `impl Future> + '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> + '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>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + '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> + Captures2<'a, 'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type must only reference lifetimes captured by this impl trait + --> $DIR/signature-mismatch.rs:20:12 + | +LL | -> impl Future> + Captures<'a>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + Captures2<'a, 'b>` + +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/signature-mismatch.rs:58:10 + | +LL | ) -> impl Future> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future>` will meet its required lifetime bounds... + | +note: ...that is required by this bound + --> $DIR/signature-mismatch.rs:25:42 + | +LL | ) -> impl Future> + '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`. diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.rs b/tests/ui/impl-trait/in-trait/signature-mismatch.rs index c562441774ec3..23dd71acecb96 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.rs +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.rs @@ -7,8 +7,27 @@ use std::future::Future; +trait Captures<'a> {} +impl Captures<'_> for T {} + +trait Captures2<'a, 'b> {} +impl Captures2<'_, '_> for T {} + pub trait AsyncTrait { fn async_fn(&self, buff: &[u8]) -> impl Future>; + fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future>; + fn async_fn_multiple<'a>(&'a self, buff: &[u8]) + -> impl Future> + Captures<'a>; + fn async_fn_reduce_outlive<'a, T>( + &'a self, + buff: &[u8], + t: T, + ) -> impl Future> + 'a; + fn async_fn_reduce<'a, T>( + &'a self, + buff: &[u8], + t: T, + ) -> impl Future> + Captures<'a>; } pub struct Struct; @@ -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> + '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> + 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> { + //~^ 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> { + async move { + let _t = t; + vec![] + } + } } fn main() {}