From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/impl-trait/in-trait/foreign.rs | 4 ++ .../impl-trait/in-trait/issue-102140.next.stderr | 6 +- .../in-trait/method-signature-matches.lt.stderr | 21 ++++++ .../method-signature-matches.mismatch.stderr | 20 ++++++ .../method-signature-matches.mismatch_async.stderr | 20 ++++++ .../in-trait/method-signature-matches.rs | 21 ++++-- .../in-trait/method-signature-matches.stderr | 74 ---------------------- .../method-signature-matches.too_few.stderr | 12 ++++ .../method-signature-matches.too_many.stderr | 12 ++++ .../return-dont-satisfy-bounds.current.stderr | 16 +++++ .../return-dont-satisfy-bounds.next.stderr | 16 +++++ .../in-trait/return-dont-satisfy-bounds.rs | 19 ++++++ .../in-trait/signature-mismatch.current.stderr | 65 ++++++++++++++++--- .../in-trait/signature-mismatch.next.stderr | 65 ++++++++++++++++--- tests/ui/impl-trait/in-trait/signature-mismatch.rs | 55 +++++++++++++++- .../impl-trait/in-trait/suggest-missing-item.fixed | 25 ++++++++ .../ui/impl-trait/in-trait/suggest-missing-item.rs | 21 ++++++ .../in-trait/suggest-missing-item.stderr | 21 ++++++ .../in-trait/unconstrained-lt.current.stderr | 9 +++ .../in-trait/unconstrained-lt.next.stderr | 9 +++ tests/ui/impl-trait/in-trait/unconstrained-lt.rs | 16 +++++ tests/ui/impl-trait/in-trait/variances-of-gat.rs | 19 ++++++ .../impl-trait/in-trait/wf-bounds.current.stderr | 27 ++++++-- tests/ui/impl-trait/in-trait/wf-bounds.next.stderr | 27 ++++++-- tests/ui/impl-trait/in-trait/wf-bounds.rs | 7 ++ 25 files changed, 492 insertions(+), 115 deletions(-) create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr delete mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr create mode 100644 tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.current.stderr create mode 100644 tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.next.stderr create mode 100644 tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.rs create mode 100644 tests/ui/impl-trait/in-trait/suggest-missing-item.fixed create mode 100644 tests/ui/impl-trait/in-trait/suggest-missing-item.rs create mode 100644 tests/ui/impl-trait/in-trait/suggest-missing-item.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr create mode 100644 tests/ui/impl-trait/in-trait/unconstrained-lt.rs create mode 100644 tests/ui/impl-trait/in-trait/variances-of-gat.rs (limited to 'tests/ui/impl-trait/in-trait') diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs index 98417b343..b0fbe3a3d 100644 --- a/tests/ui/impl-trait/in-trait/foreign.rs +++ b/tests/ui/impl-trait/in-trait/foreign.rs @@ -14,6 +14,10 @@ impl Foo for Local { fn bar(self) -> Arc { Arc::new(String::new()) } } +fn generic(f: impl Foo) { + let x = &*f.bar(); +} + fn main() { // Witness an RPITIT from another crate. let &() = Foreign.bar(); diff --git a/tests/ui/impl-trait/in-trait/issue-102140.next.stderr b/tests/ui/impl-trait/in-trait/issue-102140.next.stderr index 7aa7880e2..94893c9e7 100644 --- a/tests/ui/impl-trait/in-trait/issue-102140.next.stderr +++ b/tests/ui/impl-trait/in-trait/issue-102140.next.stderr @@ -6,11 +6,7 @@ LL | MyTrait::foo(&self) | | | required by a bound introduced by this call | -help: consider removing the leading `&`-reference - | -LL - MyTrait::foo(&self) -LL + MyTrait::foo(self) - | + = help: the trait `MyTrait` is implemented for `Outer` error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied --> $DIR/issue-102140.rs:26:9 diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr new file mode 100644 index 000000000..239c4b35c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.lt.stderr @@ -0,0 +1,21 @@ +error[E0053]: method `early` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:58:27 + | +LL | fn early<'late, T>(_: &'late ()) {} + | - ^^^^^^^^^ + | | | + | | expected type parameter `T`, found `()` + | | help: change the parameter type to match the trait: `&T` + | this type parameter + | +note: type in trait + --> $DIR/method-signature-matches.rs:53:28 + | +LL | fn early<'early, T>(x: &'early T) -> impl Sized; + | ^^^^^^^^^ + = note: expected signature `fn(&T)` + found signature `fn(&'late ())` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr new file mode 100644 index 000000000..d3183b92e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch.stderr @@ -0,0 +1,20 @@ +error[E0053]: method `owo` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:14:15 + | +LL | fn owo(_: u8) {} + | ^^ + | | + | expected `()`, found `u8` + | help: change the parameter type to match the trait: `()` + | +note: type in trait + --> $DIR/method-signature-matches.rs:9:15 + | +LL | fn owo(x: ()) -> impl Sized; + | ^^ + = note: expected signature `fn(())` + found signature `fn(u8)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr new file mode 100644 index 000000000..80fda1c9f --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.mismatch_async.stderr @@ -0,0 +1,20 @@ +error[E0053]: method `owo` has an incompatible type for trait + --> $DIR/method-signature-matches.rs:25:21 + | +LL | async fn owo(_: u8) {} + | ^^ + | | + | expected `()`, found `u8` + | help: change the parameter type to match the trait: `()` + | +note: type in trait + --> $DIR/method-signature-matches.rs:20:21 + | +LL | async fn owo(x: ()) {} + | ^^ + = note: expected signature `fn(()) -> _` + found signature `fn(u8) -> _` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.rs b/tests/ui/impl-trait/in-trait/method-signature-matches.rs index c848ee3f6..294f93b30 100644 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.rs +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.rs @@ -1,51 +1,62 @@ // edition: 2021 +// revisions: mismatch mismatch_async too_many too_few lt #![feature(return_position_impl_trait_in_trait, async_fn_in_trait)] #![allow(incomplete_features)] +#[cfg(mismatch)] trait Uwu { fn owo(x: ()) -> impl Sized; } +#[cfg(mismatch)] impl Uwu for () { fn owo(_: u8) {} - //~^ ERROR method `owo` has an incompatible type for trait + //[mismatch]~^ ERROR method `owo` has an incompatible type for trait } +#[cfg(mismatch_async)] trait AsyncUwu { async fn owo(x: ()) {} } +#[cfg(mismatch_async)] impl AsyncUwu for () { async fn owo(_: u8) {} - //~^ ERROR method `owo` has an incompatible type for trait + //[mismatch_async]~^ ERROR method `owo` has an incompatible type for trait } +#[cfg(too_many)] trait TooMuch { fn calm_down_please() -> impl Sized; } +#[cfg(too_many)] impl TooMuch for () { fn calm_down_please(_: (), _: (), _: ()) {} - //~^ ERROR method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 + //[too_many]~^ ERROR method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 } +#[cfg(too_few)] trait TooLittle { fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; } +#[cfg(too_few)] impl TooLittle for () { fn come_on_a_little_more_effort() {} - //~^ ERROR method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 + //[too_few]~^ ERROR method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 } +#[cfg(lt)] trait Lifetimes { fn early<'early, T>(x: &'early T) -> impl Sized; } +#[cfg(lt)] impl Lifetimes for () { fn early<'late, T>(_: &'late ()) {} - //~^ ERROR method `early` has an incompatible type for trait + //[lt]~^ ERROR method `early` has an incompatible type for trait } fn main() {} diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.stderr deleted file mode 100644 index 3ec62020e..000000000 --- a/tests/ui/impl-trait/in-trait/method-signature-matches.stderr +++ /dev/null @@ -1,74 +0,0 @@ -error[E0053]: method `owo` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:11:15 - | -LL | fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` - | -note: type in trait - --> $DIR/method-signature-matches.rs:7:15 - | -LL | fn owo(x: ()) -> impl Sized; - | ^^ - = note: expected signature `fn(())` - found signature `fn(u8)` - -error[E0053]: method `owo` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:20:21 - | -LL | async fn owo(_: u8) {} - | ^^ - | | - | expected `()`, found `u8` - | help: change the parameter type to match the trait: `()` - | -note: type in trait - --> $DIR/method-signature-matches.rs:16:21 - | -LL | async fn owo(x: ()) {} - | ^^ - = note: expected signature `fn(()) -> _` - found signature `fn(u8) -> _` - -error[E0050]: method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 - --> $DIR/method-signature-matches.rs:29:28 - | -LL | fn calm_down_please() -> impl Sized; - | ------------------------------------ trait requires 0 parameters -... -LL | fn calm_down_please(_: (), _: (), _: ()) {} - | ^^^^^^^^^^^^^^^^ expected 0 parameters, found 3 - -error[E0050]: method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 - --> $DIR/method-signature-matches.rs:38:5 - | -LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; - | ---------------- trait requires 3 parameters -... -LL | fn come_on_a_little_more_effort() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 parameters, found 0 - -error[E0053]: method `early` has an incompatible type for trait - --> $DIR/method-signature-matches.rs:47:27 - | -LL | fn early<'late, T>(_: &'late ()) {} - | - ^^^^^^^^^ - | | | - | | expected type parameter `T`, found `()` - | | help: change the parameter type to match the trait: `&'early T` - | this type parameter - | -note: type in trait - --> $DIR/method-signature-matches.rs:43:28 - | -LL | fn early<'early, T>(x: &'early T) -> impl Sized; - | ^^^^^^^^^ - = note: expected signature `fn(&'early T)` - found signature `fn(&())` - -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0050, E0053. -For more information about an error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr new file mode 100644 index 000000000..24bcfeb74 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.too_few.stderr @@ -0,0 +1,12 @@ +error[E0050]: method `come_on_a_little_more_effort` has 0 parameters but the declaration in trait `TooLittle::come_on_a_little_more_effort` has 3 + --> $DIR/method-signature-matches.rs:47:5 + | +LL | fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; + | ---------------- trait requires 3 parameters +... +LL | fn come_on_a_little_more_effort() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 parameters, found 0 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr b/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr new file mode 100644 index 000000000..616cbd290 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.too_many.stderr @@ -0,0 +1,12 @@ +error[E0050]: method `calm_down_please` has 3 parameters but the declaration in trait `TooMuch::calm_down_please` has 0 + --> $DIR/method-signature-matches.rs:36:28 + | +LL | fn calm_down_please() -> impl Sized; + | ------------------------------------ trait requires 0 parameters +... +LL | fn calm_down_please(_: (), _: (), _: ()) {} + | ^^^^^^^^^^^^^^^^ expected 0 parameters, found 3 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.current.stderr b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.current.stderr new file mode 100644 index 000000000..ff30103b7 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.current.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `impl Foo: Foo` is not satisfied + --> $DIR/return-dont-satisfy-bounds.rs:13:34 + | +LL | fn foo>(self) -> impl Foo { + | ^^^^^^^^^^^^ the trait `Foo` is not implemented for `impl Foo` + | + = help: the trait `Foo` is implemented for `Bar` +note: required by a bound in `Foo::foo::{opaque#0}` + --> $DIR/return-dont-satisfy-bounds.rs:7:30 + | +LL | fn foo(self) -> impl Foo; + | ^^^^^^ required by this bound in `Foo::foo::{opaque#0}` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.next.stderr b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.next.stderr new file mode 100644 index 000000000..7c7f7feaa --- /dev/null +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.next.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `impl Foo: Foo` is not satisfied + --> $DIR/return-dont-satisfy-bounds.rs:13:34 + | +LL | fn foo>(self) -> impl Foo { + | ^^^^^^^^^^^^ the trait `Foo` is not implemented for `impl Foo` + | + = help: the trait `Foo` is implemented for `Bar` +note: required by a bound in `Foo::{opaque#0}` + --> $DIR/return-dont-satisfy-bounds.rs:7:30 + | +LL | fn foo(self) -> impl Foo; + | ^^^^^^ required by this bound in `Foo::{opaque#0}` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.rs b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.rs new file mode 100644 index 000000000..65528f212 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.rs @@ -0,0 +1,19 @@ +// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty +// revisions: current next + +#![feature(return_position_impl_trait_in_trait)] + +trait Foo { + fn foo(self) -> impl Foo; +} + +struct Bar; + +impl Foo for Bar { + fn foo>(self) -> impl Foo { + //~^ ERROR: the trait bound `impl Foo: Foo` is not satisfied [E0277] + self + } +} + +fn main() {} 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 eba270af7..8c9dd4031 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.current.stderr @@ -1,16 +1,61 @@ -error: `impl` item signature doesn't match `trait` item signature - --> $DIR/signature-mismatch.rs:17:5 +error: return type captures more lifetimes than trait definition + --> $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:17:40 | LL | fn async_fn(&self, buff: &[u8]) -> impl Future>; - | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '3` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + 'a` + +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 | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` +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... | - = note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '3` - found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` - = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` - = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output +LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>( + | ++++ -error: aborting due to previous error +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 eba270af7..8c9dd4031 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.next.stderr @@ -1,16 +1,61 @@ -error: `impl` item signature doesn't match `trait` item signature - --> $DIR/signature-mismatch.rs:17:5 +error: return type captures more lifetimes than trait definition + --> $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:17:40 | LL | fn async_fn(&self, buff: &[u8]) -> impl Future>; - | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '3` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Future> + 'a` + +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 | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` +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... | - = note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '3` - found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` - = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` - = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output +LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>( + | ++++ -error: aborting due to previous error +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 38c902a97..23dd71ace 100644 --- a/tests/ui/impl-trait/in-trait/signature-mismatch.rs +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.rs @@ -7,17 +7,70 @@ 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; impl AsyncTrait for Struct { fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { - //~^ ERROR `impl` item signature doesn't match `trait` item signature + //~^ 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() {} diff --git a/tests/ui/impl-trait/in-trait/suggest-missing-item.fixed b/tests/ui/impl-trait/in-trait/suggest-missing-item.fixed new file mode 100644 index 000000000..d9f775a6c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/suggest-missing-item.fixed @@ -0,0 +1,25 @@ +// edition:2021 +// run-rustfix + +#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)] + +trait Trait { + async fn foo(); + + async fn bar() -> i32; + + fn test(&self) -> impl Sized + '_; + + async fn baz(&self) -> &i32; +} + +struct S; + +impl Trait for S {async fn baz(&self) -> &i32 { todo!() } +fn test(&self) -> impl Sized + '_ { todo!() } +async fn bar() -> i32 { todo!() } +async fn foo() { todo!() } +} +//~^ ERROR not all trait items implemented + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/suggest-missing-item.rs b/tests/ui/impl-trait/in-trait/suggest-missing-item.rs new file mode 100644 index 000000000..26979b514 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/suggest-missing-item.rs @@ -0,0 +1,21 @@ +// edition:2021 +// run-rustfix + +#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)] + +trait Trait { + async fn foo(); + + async fn bar() -> i32; + + fn test(&self) -> impl Sized + '_; + + async fn baz(&self) -> &i32; +} + +struct S; + +impl Trait for S {} +//~^ ERROR not all trait items implemented + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/suggest-missing-item.stderr b/tests/ui/impl-trait/in-trait/suggest-missing-item.stderr new file mode 100644 index 000000000..44f98896e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/suggest-missing-item.stderr @@ -0,0 +1,21 @@ +error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`, `baz` + --> $DIR/suggest-missing-item.rs:18:1 + | +LL | async fn foo(); + | --------------- `foo` from trait +LL | +LL | async fn bar() -> i32; + | ---------------------- `bar` from trait +LL | +LL | fn test(&self) -> impl Sized + '_; + | ---------------------------------- `test` from trait +LL | +LL | async fn baz(&self) -> &i32; + | ---------------------------- `baz` from trait +... +LL | impl Trait for S {} + | ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test`, `baz` in implementation + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0046`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr b/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr new file mode 100644 index 000000000..bf088ae8b --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.current.stderr @@ -0,0 +1,9 @@ +error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-lt.rs:10:6 + | +LL | impl<'a, T> Foo for T { + | ^^ unconstrained lifetime parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr b/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr new file mode 100644 index 000000000..bf088ae8b --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.next.stderr @@ -0,0 +1,9 @@ +error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + --> $DIR/unconstrained-lt.rs:10:6 + | +LL | impl<'a, T> Foo for T { + | ^^ unconstrained lifetime parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/impl-trait/in-trait/unconstrained-lt.rs b/tests/ui/impl-trait/in-trait/unconstrained-lt.rs new file mode 100644 index 000000000..f966be43a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unconstrained-lt.rs @@ -0,0 +1,16 @@ +// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty +// revisions: current next + +#![feature(return_position_impl_trait_in_trait)] + +trait Foo { + fn test() -> impl Sized; +} + +impl<'a, T> Foo for T { + //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates + + fn test() -> &'a () { &() } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/variances-of-gat.rs b/tests/ui/impl-trait/in-trait/variances-of-gat.rs new file mode 100644 index 000000000..4008ece94 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/variances-of-gat.rs @@ -0,0 +1,19 @@ +// check-pass +// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty +// revisions: current next + +#![feature(return_position_impl_trait_in_trait)] + +trait Foo {} + +impl Foo for () {} + +trait ThreeCellFragment { + fn ext_cells<'a>(&'a self) -> impl Foo + 'a { + self.ext_adjacent_cells() + } + + fn ext_adjacent_cells<'a>(&'a self) -> impl Foo + 'a; +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/wf-bounds.current.stderr b/tests/ui/impl-trait/in-trait/wf-bounds.current.stderr index 1a7071612..74c84c012 100644 --- a/tests/ui/impl-trait/in-trait/wf-bounds.current.stderr +++ b/tests/ui/impl-trait/in-trait/wf-bounds.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:13:22 + --> $DIR/wf-bounds.rs:17:22 | LL | fn nya() -> impl Wf>; | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -9,14 +9,14 @@ note: required by a bound in `Vec` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:16:23 + --> $DIR/wf-bounds.rs:20:23 | LL | fn nya2() -> impl Wf<[u8]>; | ^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` note: required by a bound in `Wf` - --> $DIR/wf-bounds.rs:8:10 + --> $DIR/wf-bounds.rs:10:10 | LL | trait Wf { | ^ required by this bound in `Wf` @@ -26,7 +26,7 @@ LL | trait Wf { | ++++++++ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:19:44 + --> $DIR/wf-bounds.rs:23:44 | LL | fn nya3() -> impl Wf<(), Output = impl Wf>>; | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -35,6 +35,23 @@ LL | fn nya3() -> impl Wf<(), Output = impl Wf>>; note: required by a bound in `Vec` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL -error: aborting due to 3 previous errors +error[E0277]: `T` doesn't implement `std::fmt::Display` + --> $DIR/wf-bounds.rs:26:26 + | +LL | fn nya4() -> impl Wf>; + | ^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted with the default formatter + | + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `NeedsDisplay` + --> $DIR/wf-bounds.rs:14:24 + | +LL | struct NeedsDisplay(T); + | ^^^^^^^ required by this bound in `NeedsDisplay` +help: consider restricting type parameter `T` + | +LL | fn nya4() -> impl Wf>; + | +++++++++++++++++++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/wf-bounds.next.stderr b/tests/ui/impl-trait/in-trait/wf-bounds.next.stderr index 1a7071612..74c84c012 100644 --- a/tests/ui/impl-trait/in-trait/wf-bounds.next.stderr +++ b/tests/ui/impl-trait/in-trait/wf-bounds.next.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:13:22 + --> $DIR/wf-bounds.rs:17:22 | LL | fn nya() -> impl Wf>; | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -9,14 +9,14 @@ note: required by a bound in `Vec` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:16:23 + --> $DIR/wf-bounds.rs:20:23 | LL | fn nya2() -> impl Wf<[u8]>; | ^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` note: required by a bound in `Wf` - --> $DIR/wf-bounds.rs:8:10 + --> $DIR/wf-bounds.rs:10:10 | LL | trait Wf { | ^ required by this bound in `Wf` @@ -26,7 +26,7 @@ LL | trait Wf { | ++++++++ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/wf-bounds.rs:19:44 + --> $DIR/wf-bounds.rs:23:44 | LL | fn nya3() -> impl Wf<(), Output = impl Wf>>; | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -35,6 +35,23 @@ LL | fn nya3() -> impl Wf<(), Output = impl Wf>>; note: required by a bound in `Vec` --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL -error: aborting due to 3 previous errors +error[E0277]: `T` doesn't implement `std::fmt::Display` + --> $DIR/wf-bounds.rs:26:26 + | +LL | fn nya4() -> impl Wf>; + | ^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted with the default formatter + | + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `NeedsDisplay` + --> $DIR/wf-bounds.rs:14:24 + | +LL | struct NeedsDisplay(T); + | ^^^^^^^ required by this bound in `NeedsDisplay` +help: consider restricting type parameter `T` + | +LL | fn nya4() -> impl Wf>; + | +++++++++++++++++++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/wf-bounds.rs b/tests/ui/impl-trait/in-trait/wf-bounds.rs index 1c9590bd8..f8c1e561d 100644 --- a/tests/ui/impl-trait/in-trait/wf-bounds.rs +++ b/tests/ui/impl-trait/in-trait/wf-bounds.rs @@ -5,10 +5,14 @@ #![feature(return_position_impl_trait_in_trait)] #![allow(incomplete_features)] +use std::fmt::Display; + trait Wf { type Output; } +struct NeedsDisplay(T); + trait Uwu { fn nya() -> impl Wf>; //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time @@ -18,6 +22,9 @@ trait Uwu { fn nya3() -> impl Wf<(), Output = impl Wf>>; //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time + + fn nya4() -> impl Wf>; + //~^ ERROR `T` doesn't implement `std::fmt::Display` } fn main() {} -- cgit v1.2.3