From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs | 11 +++ .../in-trait/box-coerce-span-in-default.rs | 49 +++++++++++++ .../in-trait/box-coerce-span-in-default.stderr | 11 +++ tests/ui/impl-trait/in-trait/deep-match-works.rs | 16 +++++ tests/ui/impl-trait/in-trait/deep-match.rs | 15 ++++ tests/ui/impl-trait/in-trait/deep-match.stderr | 15 ++++ .../impl-trait/in-trait/default-body-type-err-2.rs | 13 ++++ .../in-trait/default-body-type-err-2.stderr | 11 +++ .../impl-trait/in-trait/default-body-type-err.rs | 13 ++++ .../in-trait/default-body-type-err.stderr | 12 ++++ .../impl-trait/in-trait/default-body-with-rpit.rs | 21 ++++++ tests/ui/impl-trait/in-trait/default-body.rs | 21 ++++++ tests/ui/impl-trait/in-trait/doesnt-satisfy.rs | 13 ++++ tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr | 17 +++++ tests/ui/impl-trait/in-trait/early.rs | 23 ++++++ tests/ui/impl-trait/in-trait/encode.rs | 9 +++ tests/ui/impl-trait/in-trait/foreign.rs | 9 +++ tests/ui/impl-trait/in-trait/generics-mismatch.rs | 17 +++++ .../impl-trait/in-trait/generics-mismatch.stderr | 12 ++++ tests/ui/impl-trait/in-trait/issue-102140.rs | 30 ++++++++ tests/ui/impl-trait/in-trait/issue-102140.stderr | 33 +++++++++ tests/ui/impl-trait/in-trait/issue-102301.rs | 18 +++++ tests/ui/impl-trait/in-trait/issue-102571.rs | 24 +++++++ tests/ui/impl-trait/in-trait/issue-102571.stderr | 14 ++++ .../in-trait/method-signature-matches.rs | 51 +++++++++++++ .../in-trait/method-signature-matches.stderr | 84 ++++++++++++++++++++++ tests/ui/impl-trait/in-trait/nested-rpitit.rs | 32 +++++++++ tests/ui/impl-trait/in-trait/object-safety.rs | 22 ++++++ tests/ui/impl-trait/in-trait/object-safety.stderr | 50 +++++++++++++ .../in-trait/opaque-in-impl-is-opaque.rs | 19 +++++ .../in-trait/opaque-in-impl-is-opaque.stderr | 17 +++++ tests/ui/impl-trait/in-trait/opaque-in-impl.rs | 48 +++++++++++++ tests/ui/impl-trait/in-trait/reveal.rs | 18 +++++ tests/ui/impl-trait/in-trait/signature-mismatch.rs | 21 ++++++ .../impl-trait/in-trait/signature-mismatch.stderr | 16 +++++ .../impl-trait/in-trait/specialization-broken.rs | 26 +++++++ .../in-trait/specialization-broken.stderr | 23 ++++++ .../in-trait/specialization-substs-remap.rs | 24 +++++++ tests/ui/impl-trait/in-trait/success.rs | 40 +++++++++++ .../in-trait/trait-more-generics-than-impl.rs | 17 +++++ .../in-trait/trait-more-generics-than-impl.stderr | 12 ++++ tests/ui/impl-trait/in-trait/wf-bounds.rs | 16 +++++ tests/ui/impl-trait/in-trait/wf-bounds.stderr | 30 ++++++++ tests/ui/impl-trait/in-trait/where-clause.rs | 24 +++++++ 44 files changed, 1017 insertions(+) create mode 100644 tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs create mode 100644 tests/ui/impl-trait/in-trait/box-coerce-span-in-default.rs create mode 100644 tests/ui/impl-trait/in-trait/box-coerce-span-in-default.stderr create mode 100644 tests/ui/impl-trait/in-trait/deep-match-works.rs create mode 100644 tests/ui/impl-trait/in-trait/deep-match.rs create mode 100644 tests/ui/impl-trait/in-trait/deep-match.stderr create mode 100644 tests/ui/impl-trait/in-trait/default-body-type-err-2.rs create mode 100644 tests/ui/impl-trait/in-trait/default-body-type-err-2.stderr create mode 100644 tests/ui/impl-trait/in-trait/default-body-type-err.rs create mode 100644 tests/ui/impl-trait/in-trait/default-body-type-err.stderr create mode 100644 tests/ui/impl-trait/in-trait/default-body-with-rpit.rs create mode 100644 tests/ui/impl-trait/in-trait/default-body.rs create mode 100644 tests/ui/impl-trait/in-trait/doesnt-satisfy.rs create mode 100644 tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr create mode 100644 tests/ui/impl-trait/in-trait/early.rs create mode 100644 tests/ui/impl-trait/in-trait/encode.rs create mode 100644 tests/ui/impl-trait/in-trait/foreign.rs create mode 100644 tests/ui/impl-trait/in-trait/generics-mismatch.rs create mode 100644 tests/ui/impl-trait/in-trait/generics-mismatch.stderr create mode 100644 tests/ui/impl-trait/in-trait/issue-102140.rs create mode 100644 tests/ui/impl-trait/in-trait/issue-102140.stderr create mode 100644 tests/ui/impl-trait/in-trait/issue-102301.rs create mode 100644 tests/ui/impl-trait/in-trait/issue-102571.rs create mode 100644 tests/ui/impl-trait/in-trait/issue-102571.stderr create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.rs create mode 100644 tests/ui/impl-trait/in-trait/method-signature-matches.stderr create mode 100644 tests/ui/impl-trait/in-trait/nested-rpitit.rs create mode 100644 tests/ui/impl-trait/in-trait/object-safety.rs create mode 100644 tests/ui/impl-trait/in-trait/object-safety.stderr create mode 100644 tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs create mode 100644 tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr create mode 100644 tests/ui/impl-trait/in-trait/opaque-in-impl.rs create mode 100644 tests/ui/impl-trait/in-trait/reveal.rs create mode 100644 tests/ui/impl-trait/in-trait/signature-mismatch.rs create mode 100644 tests/ui/impl-trait/in-trait/signature-mismatch.stderr create mode 100644 tests/ui/impl-trait/in-trait/specialization-broken.rs create mode 100644 tests/ui/impl-trait/in-trait/specialization-broken.stderr create mode 100644 tests/ui/impl-trait/in-trait/specialization-substs-remap.rs create mode 100644 tests/ui/impl-trait/in-trait/success.rs create mode 100644 tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs create mode 100644 tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr create mode 100644 tests/ui/impl-trait/in-trait/wf-bounds.rs create mode 100644 tests/ui/impl-trait/in-trait/wf-bounds.stderr create mode 100644 tests/ui/impl-trait/in-trait/where-clause.rs (limited to 'tests/ui/impl-trait/in-trait') diff --git a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs new file mode 100644 index 000000000..74df300f8 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs @@ -0,0 +1,11 @@ +#![feature(return_position_impl_trait_in_trait)] + +pub trait Foo { + fn bar() -> impl Sized; +} + +pub struct Foreign; + +impl Foo for Foreign { + fn bar() {} +} diff --git a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.rs b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.rs new file mode 100644 index 000000000..a4d483dee --- /dev/null +++ b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.rs @@ -0,0 +1,49 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete + +struct TestA {} +struct TestB {} + +impl TestTrait for TestA { + type Output = (); +} +impl TestTrait for TestB { + type Output = (); +} + +trait TestTrait { + type Output; +} + +impl TestTrait for GreeterOutput +where + A: TestTrait, + B: TestTrait, +{ + type Output = (); +} + +enum GreeterOutput +where + A: TestTrait, + B: TestTrait, +{ + SayHello(A), + SayGoodbye(B), +} + +trait Greeter { + fn test_func(&self, func: &str) -> impl TestTrait { + match func { + "SayHello" => GreeterOutput::SayHello(TestA {}), + "SayGoodbye" => GreeterOutput::SayGoodbye(TestB {}), + _ => GreeterOutput::SayHello(TestA {}), + } + } +} + +fn main() { + println!("Hello, world!"); +} diff --git a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.stderr b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.stderr new file mode 100644 index 000000000..d681ecf25 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.stderr @@ -0,0 +1,11 @@ +warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/box-coerce-span-in-default.rs:3:12 + | +LL | #![feature(return_position_impl_trait_in_trait)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #91611 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/impl-trait/in-trait/deep-match-works.rs b/tests/ui/impl-trait/in-trait/deep-match-works.rs new file mode 100644 index 000000000..772da845e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/deep-match-works.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +struct Wrapper(T); + +trait Foo { + fn bar() -> Wrapper; +} + +impl Foo for () { + fn bar() -> Wrapper { Wrapper(0) } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/deep-match.rs b/tests/ui/impl-trait/in-trait/deep-match.rs new file mode 100644 index 000000000..a6385147c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/deep-match.rs @@ -0,0 +1,15 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +struct Wrapper(T); + +trait Foo { + fn bar() -> Wrapper; +} + +impl Foo for () { + fn bar() -> i32 { 0 } + //~^ ERROR method `bar` has an incompatible return type for trait +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/deep-match.stderr b/tests/ui/impl-trait/in-trait/deep-match.stderr new file mode 100644 index 000000000..034ee5ea4 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/deep-match.stderr @@ -0,0 +1,15 @@ +error[E0053]: method `bar` has an incompatible return type for trait + --> $DIR/deep-match.rs:11:17 + | +LL | fn bar() -> i32 { 0 } + | ^^^ + | | + | expected struct `Wrapper`, found `i32` + | return type in trait + | + = note: expected struct `Wrapper<_>` + found type `i32` + +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/default-body-type-err-2.rs b/tests/ui/impl-trait/in-trait/default-body-type-err-2.rs new file mode 100644 index 000000000..45ae2b8ad --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body-type-err-2.rs @@ -0,0 +1,13 @@ +// edition:2021 + +#![allow(incomplete_features)] +#![feature(async_fn_in_trait)] + +pub trait Foo { + async fn woopsie_async(&self) -> String { + 42 + //~^ ERROR mismatched types + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/default-body-type-err-2.stderr b/tests/ui/impl-trait/in-trait/default-body-type-err-2.stderr new file mode 100644 index 000000000..142b1bff1 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body-type-err-2.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/default-body-type-err-2.rs:8:9 + | +LL | 42 + | ^^- help: try using a conversion method: `.to_string()` + | | + | expected struct `String`, found integer + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/in-trait/default-body-type-err.rs b/tests/ui/impl-trait/in-trait/default-body-type-err.rs new file mode 100644 index 000000000..ac9baf91c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body-type-err.rs @@ -0,0 +1,13 @@ +#![allow(incomplete_features)] +#![feature(return_position_impl_trait_in_trait)] + +use std::ops::Deref; + +pub trait Foo { + fn lol(&self) -> impl Deref { + //~^ type mismatch resolving `<&i32 as Deref>::Target == String` + &1i32 + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/default-body-type-err.stderr b/tests/ui/impl-trait/in-trait/default-body-type-err.stderr new file mode 100644 index 000000000..461247a3e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body-type-err.stderr @@ -0,0 +1,12 @@ +error[E0271]: type mismatch resolving `<&i32 as Deref>::Target == String` + --> $DIR/default-body-type-err.rs:7:22 + | +LL | fn lol(&self) -> impl Deref { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String` +LL | +LL | &1i32 + | ----- return type was inferred to be `&i32` here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/impl-trait/in-trait/default-body-with-rpit.rs b/tests/ui/impl-trait/in-trait/default-body-with-rpit.rs new file mode 100644 index 000000000..ad3cc7c25 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body-with-rpit.rs @@ -0,0 +1,21 @@ +// check-pass +// edition:2021 + +#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo { + async fn baz(&self) -> impl Debug { + "" + } +} + +struct Bar; + +impl Foo for Bar {} + +fn main() { + let _ = Bar.baz(); +} diff --git a/tests/ui/impl-trait/in-trait/default-body.rs b/tests/ui/impl-trait/in-trait/default-body.rs new file mode 100644 index 000000000..b0baf5bb1 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/default-body.rs @@ -0,0 +1,21 @@ +// check-pass +// edition:2021 + +#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo { + async fn baz(&self) -> &str { + "" + } +} + +struct Bar; + +impl Foo for Bar {} + +fn main() { + let _ = Bar.baz(); +} diff --git a/tests/ui/impl-trait/in-trait/doesnt-satisfy.rs b/tests/ui/impl-trait/in-trait/doesnt-satisfy.rs new file mode 100644 index 000000000..bb4e0d44f --- /dev/null +++ b/tests/ui/impl-trait/in-trait/doesnt-satisfy.rs @@ -0,0 +1,13 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn bar() -> impl std::fmt::Display; +} + +impl Foo for () { + fn bar() -> () {} + //~^ ERROR `()` doesn't implement `std::fmt::Display` +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr new file mode 100644 index 000000000..aa5492d28 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr @@ -0,0 +1,17 @@ +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/doesnt-satisfy.rs:9:17 + | +LL | fn bar() -> () {} + | ^^ `()` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `Foo::bar::{opaque#0}` + --> $DIR/doesnt-satisfy.rs:5:22 + | +LL | fn bar() -> impl std::fmt::Display; + | ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::bar::{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/early.rs b/tests/ui/impl-trait/in-trait/early.rs new file mode 100644 index 000000000..9c1c2b503 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/early.rs @@ -0,0 +1,23 @@ +// check-pass +// edition:2021 + +#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +pub trait Foo { + async fn bar<'a: 'a>(&'a mut self); +} + +impl Foo for () { + async fn bar<'a: 'a>(&'a mut self) {} +} + +pub trait Foo2 { + fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a; +} + +impl Foo2 for () { + fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {} +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/encode.rs b/tests/ui/impl-trait/in-trait/encode.rs new file mode 100644 index 000000000..efb9f6498 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/encode.rs @@ -0,0 +1,9 @@ +// build-pass +// compile-flags: --crate-type=lib + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn bar() -> impl Sized; +} diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs new file mode 100644 index 000000000..6341f5b42 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/foreign.rs @@ -0,0 +1,9 @@ +// check-pass +// aux-build: rpitit.rs + +extern crate rpitit; + +fn main() { + // Witness an RPITIT from another crate + let () = ::bar(); +} diff --git a/tests/ui/impl-trait/in-trait/generics-mismatch.rs b/tests/ui/impl-trait/in-trait/generics-mismatch.rs new file mode 100644 index 000000000..cc0fc720e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/generics-mismatch.rs @@ -0,0 +1,17 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +struct U; + +trait Foo { + fn bar(&self) -> impl Sized; +} + +impl Foo for U { + fn bar(&self) {} + //~^ ERROR method `bar` has 1 type parameter but its trait declaration has 0 type parameters +} + +fn main() { + U.bar(); +} diff --git a/tests/ui/impl-trait/in-trait/generics-mismatch.stderr b/tests/ui/impl-trait/in-trait/generics-mismatch.stderr new file mode 100644 index 000000000..cd42683e0 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/generics-mismatch.stderr @@ -0,0 +1,12 @@ +error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters + --> $DIR/generics-mismatch.rs:11:12 + | +LL | fn bar(&self) -> impl Sized; + | - expected 0 type parameters +... +LL | fn bar(&self) {} + | ^ found 1 type parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0049`. diff --git a/tests/ui/impl-trait/in-trait/issue-102140.rs b/tests/ui/impl-trait/in-trait/issue-102140.rs new file mode 100644 index 000000000..be1e012ac --- /dev/null +++ b/tests/ui/impl-trait/in-trait/issue-102140.rs @@ -0,0 +1,30 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Marker {} +impl Marker for u32 {} + +trait MyTrait { + fn foo(&self) -> impl Marker + where + Self: Sized; +} + +struct Outer; + +impl MyTrait for Outer { + fn foo(&self) -> impl Marker { + 42 + } +} + +impl dyn MyTrait { + fn other(&self) -> impl Marker { + MyTrait::foo(&self) + //~^ ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied + //~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied + //~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/issue-102140.stderr b/tests/ui/impl-trait/in-trait/issue-102140.stderr new file mode 100644 index 000000000..18bb63745 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/issue-102140.stderr @@ -0,0 +1,33 @@ +error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied + --> $DIR/issue-102140.rs:23:22 + | +LL | MyTrait::foo(&self) + | ------------ ^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` + | | + | required by a bound introduced by this call + | +help: consider removing the leading `&`-reference + | +LL - MyTrait::foo(&self) +LL + MyTrait::foo(self) + | + +error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied + --> $DIR/issue-102140.rs:23:9 + | +LL | MyTrait::foo(&self) + | ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` + | + = help: the trait `MyTrait` is implemented for `Outer` + +error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied + --> $DIR/issue-102140.rs:23:9 + | +LL | MyTrait::foo(&self) + | ^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` + | + = help: the trait `MyTrait` is implemented for `Outer` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/issue-102301.rs b/tests/ui/impl-trait/in-trait/issue-102301.rs new file mode 100644 index 000000000..a93714a65 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/issue-102301.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn foo>(self) -> impl Foo; +} + +struct Bar; + +impl Foo for Bar { + fn foo>(self) -> impl Foo { + self + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/issue-102571.rs b/tests/ui/impl-trait/in-trait/issue-102571.rs new file mode 100644 index 000000000..61c91e644 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/issue-102571.rs @@ -0,0 +1,24 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Display; +use std::ops::Deref; + +trait Foo { + fn bar(self) -> impl Deref; +} + +struct A; + +impl Foo for A { + fn bar(self) -> &'static str { + "Hello, world" + } +} + +fn foo(t: T) { + let () = t.bar(); + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/issue-102571.stderr b/tests/ui/impl-trait/in-trait/issue-102571.stderr new file mode 100644 index 000000000..87219941d --- /dev/null +++ b/tests/ui/impl-trait/in-trait/issue-102571.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-102571.rs:20:9 + | +LL | let () = t.bar(); + | ^^ ------- this expression has type `impl Deref` + | | + | expected associated type, found `()` + | + = note: expected associated type `impl Deref` + found unit type `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/in-trait/method-signature-matches.rs b/tests/ui/impl-trait/in-trait/method-signature-matches.rs new file mode 100644 index 000000000..c848ee3f6 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.rs @@ -0,0 +1,51 @@ +// edition: 2021 + +#![feature(return_position_impl_trait_in_trait, async_fn_in_trait)] +#![allow(incomplete_features)] + +trait Uwu { + fn owo(x: ()) -> impl Sized; +} + +impl Uwu for () { + fn owo(_: u8) {} + //~^ ERROR method `owo` has an incompatible type for trait +} + +trait AsyncUwu { + async fn owo(x: ()) {} +} + +impl AsyncUwu for () { + async fn owo(_: u8) {} + //~^ ERROR method `owo` has an incompatible type for trait +} + +trait TooMuch { + fn calm_down_please() -> impl Sized; +} + +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 +} + +trait TooLittle { + fn come_on_a_little_more_effort(_: (), _: (), _: ()) -> impl Sized; +} + +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 +} + +trait Lifetimes { + fn early<'early, T>(x: &'early T) -> impl Sized; +} + +impl Lifetimes for () { + fn early<'late, T>(_: &'late ()) {} + //~^ 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 new file mode 100644 index 000000000..4dfd77222 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/method-signature-matches.stderr @@ -0,0 +1,84 @@ +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: while checking the return type of the `async fn` + --> $DIR/method-signature-matches.rs:20:25 + | +LL | async fn owo(_: u8) {} + | ^ checked the `Output` of this `async fn`, expected opaque type +note: while checking the return type of the `async fn` + --> $DIR/method-signature-matches.rs:20:25 + | +LL | async fn owo(_: u8) {} + | ^ checked the `Output` of this `async fn`, found opaque type +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/nested-rpitit.rs b/tests/ui/impl-trait/in-trait/nested-rpitit.rs new file mode 100644 index 000000000..65285e3a3 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/nested-rpitit.rs @@ -0,0 +1,32 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Display; +use std::ops::Deref; + +trait Foo { + fn bar(self) -> impl Deref; +} + +struct A; + +impl Foo for A { + fn bar(self) -> &'static str { + "Hello, world" + } +} + +struct B; + +impl Foo for B { + fn bar(self) -> Box { + Box::new(42) + } +} + +fn main() { + println!("Message for you: {:?}", &*A.bar()); + println!("Another for you: {:?}", &*B.bar()); +} diff --git a/tests/ui/impl-trait/in-trait/object-safety.rs b/tests/ui/impl-trait/in-trait/object-safety.rs new file mode 100644 index 000000000..dd35b9a2d --- /dev/null +++ b/tests/ui/impl-trait/in-trait/object-safety.rs @@ -0,0 +1,22 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo { + fn baz(&self) -> impl Debug; +} + +impl Foo for u32 { + fn baz(&self) -> u32 { + 32 + } +} + +fn main() { + let i = Box::new(42_u32) as Box; + //~^ ERROR the trait `Foo` cannot be made into an object + //~| ERROR the trait `Foo` cannot be made into an object + let s = i.baz(); + //~^ ERROR the trait `Foo` cannot be made into an object +} diff --git a/tests/ui/impl-trait/in-trait/object-safety.stderr b/tests/ui/impl-trait/in-trait/object-safety.stderr new file mode 100644 index 000000000..ca0e760ff --- /dev/null +++ b/tests/ui/impl-trait/in-trait/object-safety.stderr @@ -0,0 +1,50 @@ +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/object-safety.rs:17:33 + | +LL | let i = Box::new(42_u32) as Box; + | ^^^^^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/object-safety.rs:7:22 + | +LL | trait Foo { + | --- this trait cannot be made into an object... +LL | fn baz(&self) -> impl Debug; + | ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type + = help: consider moving `baz` to another trait + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/object-safety.rs:20:13 + | +LL | let s = i.baz(); + | ^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/object-safety.rs:7:22 + | +LL | trait Foo { + | --- this trait cannot be made into an object... +LL | fn baz(&self) -> impl Debug; + | ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type + = help: consider moving `baz` to another trait + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/object-safety.rs:17:13 + | +LL | let i = Box::new(42_u32) as Box; + | ^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/object-safety.rs:7:22 + | +LL | trait Foo { + | --- this trait cannot be made into an object... +LL | fn baz(&self) -> impl Debug; + | ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type + = help: consider moving `baz` to another trait + = note: required for `Box` to implement `CoerceUnsized>` + = note: required by cast to type `Box` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs new file mode 100644 index 000000000..3ac264e8e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs @@ -0,0 +1,19 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Display; + +trait Foo { + fn bar(&self) -> impl Display; +} + +impl Foo for () { + fn bar(&self) -> impl Display { + "Hello, world" + } +} + +fn main() { + let x: &str = ().bar(); + //~^ ERROR mismatched types +} diff --git a/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr new file mode 100644 index 000000000..15edda483 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/opaque-in-impl-is-opaque.rs:17:19 + | +LL | fn bar(&self) -> impl Display { + | ------------ the found opaque type +... +LL | let x: &str = ().bar(); + | ---- ^^^^^^^^ expected `&str`, found opaque type + | | + | expected due to this + | + = note: expected reference `&str` + found opaque type `impl std::fmt::Display` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/in-trait/opaque-in-impl.rs b/tests/ui/impl-trait/in-trait/opaque-in-impl.rs new file mode 100644 index 000000000..2e0662969 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/opaque-in-impl.rs @@ -0,0 +1,48 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo { + fn foo(&self) -> impl Debug; +} + +impl Foo for () { + fn foo(&self) -> impl Debug { + "Hello, world" + } +} + +impl Foo for std::marker::PhantomData { + fn foo(&self) -> impl Debug { + T::default() + } +} + +trait Bar { + fn bar(&self) -> impl Debug; +} + +impl Bar for () { + fn bar(&self) -> impl Debug { + format!("Hello with generic {}", std::any::type_name::()) + } +} + +trait Baz { + fn baz(&self) -> impl Debug + '_; +} + +impl Baz for String { + fn baz(&self) -> impl Debug + '_ { + (self,) + } +} + +fn main() { + println!("{:?}", ().foo()); + println!("{:?}", ().bar::()); + println!("{:?}", "hi".to_string().baz()); +} diff --git a/tests/ui/impl-trait/in-trait/reveal.rs b/tests/ui/impl-trait/in-trait/reveal.rs new file mode 100644 index 000000000..d6ede1cc4 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/reveal.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn f() -> Box; +} + +impl Foo for () { + fn f() -> Box { + Box::new(String::new()) + } +} + +fn main() { + let x: Box = <() as Foo>::f(); +} diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.rs b/tests/ui/impl-trait/in-trait/signature-mismatch.rs new file mode 100644 index 000000000..90682631a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.rs @@ -0,0 +1,21 @@ +// edition:2021 + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; + +pub trait AsyncTrait { + fn async_fn(&self, buff: &[u8]) -> impl Future>; +} + +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 + async move { buff.to_vec() } + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/signature-mismatch.stderr b/tests/ui/impl-trait/in-trait/signature-mismatch.stderr new file mode 100644 index 000000000..e10566017 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/signature-mismatch.stderr @@ -0,0 +1,16 @@ +error: `impl` item signature doesn't match `trait` item signature + --> $DIR/signature-mismatch.rs:15:5 + | +LL | fn async_fn(&self, buff: &[u8]) -> impl Future>; + | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future> + 'static` +... +LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` + | + = note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future> + 'static` + 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 + +error: aborting due to previous error + diff --git a/tests/ui/impl-trait/in-trait/specialization-broken.rs b/tests/ui/impl-trait/in-trait/specialization-broken.rs new file mode 100644 index 000000000..9d27d3710 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/specialization-broken.rs @@ -0,0 +1,26 @@ +// FIXME(compiler-errors): I'm not exactly sure if this is expected to pass or not. +// But we fixed an ICE anyways. + +#![feature(specialization)] +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn bar(&self) -> impl Sized; +} + +default impl Foo for U +where + U: Copy, +{ + fn bar(&self) -> U { + //~^ ERROR method `bar` has an incompatible type for trait + *self + } +} + +impl Foo for i32 {} + +fn main() { + 1i32.bar(); +} diff --git a/tests/ui/impl-trait/in-trait/specialization-broken.stderr b/tests/ui/impl-trait/in-trait/specialization-broken.stderr new file mode 100644 index 000000000..37cfd7449 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/specialization-broken.stderr @@ -0,0 +1,23 @@ +error[E0053]: method `bar` has an incompatible type for trait + --> $DIR/specialization-broken.rs:16:22 + | +LL | default impl Foo for U + | - this type parameter +... +LL | fn bar(&self) -> U { + | ^ + | | + | expected associated type, found type parameter `U` + | help: change the output type to match the trait: `impl Sized` + | +note: type in trait + --> $DIR/specialization-broken.rs:9:22 + | +LL | fn bar(&self) -> impl Sized; + | ^^^^^^^^^^ + = note: expected signature `fn(&U) -> impl Sized` + found signature `fn(&U) -> U` + +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/specialization-substs-remap.rs b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs new file mode 100644 index 000000000..c9ee877db --- /dev/null +++ b/tests/ui/impl-trait/in-trait/specialization-substs-remap.rs @@ -0,0 +1,24 @@ +// check-pass + +#![feature(specialization)] +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Foo { + fn bar(&self) -> impl Sized; +} + +impl Foo for U +where + U: Copy, +{ + fn bar(&self) -> U { + *self + } +} + +impl Foo for i32 {} + +fn main() { + let _: i32 = 1i32.bar(); +} diff --git a/tests/ui/impl-trait/in-trait/success.rs b/tests/ui/impl-trait/in-trait/success.rs new file mode 100644 index 000000000..4cbe682b4 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/success.rs @@ -0,0 +1,40 @@ +// check-pass + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Display; + +trait Foo { + fn bar(&self) -> impl Display; +} + +impl Foo for i32 { + fn bar(&self) -> i32 { + *self + } +} + +impl Foo for &'static str { + fn bar(&self) -> &'static str { + *self + } +} + +struct Yay; + +impl Foo for Yay { + fn bar(&self) -> String { + String::from(":^)") + } +} + +fn foo_generically(t: T) { + println!("{}", t.bar()); +} + +fn main() { + println!("{}", "Hello, world.".bar()); + println!("The answer is {}!", 42.bar()); + foo_generically(Yay); +} diff --git a/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs b/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs new file mode 100644 index 000000000..0bbe50ea6 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.rs @@ -0,0 +1,17 @@ +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +struct S; + +trait Foo { + fn bar() -> impl Sized; +} + +impl Foo for S { + fn bar() -> impl Sized {} + //~^ ERROR method `bar` has 0 type parameters but its trait declaration has 1 type parameter +} + +fn main() { + S::bar(); +} diff --git a/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr b/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr new file mode 100644 index 000000000..8ff54cad9 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/trait-more-generics-than-impl.stderr @@ -0,0 +1,12 @@ +error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter + --> $DIR/trait-more-generics-than-impl.rs:11:11 + | +LL | fn bar() -> impl Sized; + | - expected 1 type parameter +... +LL | fn bar() -> impl Sized {} + | ^ found 0 type parameters + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0049`. diff --git a/tests/ui/impl-trait/in-trait/wf-bounds.rs b/tests/ui/impl-trait/in-trait/wf-bounds.rs new file mode 100644 index 000000000..2c71583b3 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/wf-bounds.rs @@ -0,0 +1,16 @@ +// issue #101663 + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +trait Wf {} + +trait Uwu { + fn nya() -> impl Wf>; + //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time + + fn nya2() -> impl Wf<[u8]>; + //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/wf-bounds.stderr b/tests/ui/impl-trait/in-trait/wf-bounds.stderr new file mode 100644 index 000000000..03cc4c2b9 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/wf-bounds.stderr @@ -0,0 +1,30 @@ +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/wf-bounds.rs:9:22 + | +LL | fn nya() -> impl Wf>; + | ^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[u8]` +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:12: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:6:10 + | +LL | trait Wf {} + | ^ required by this bound in `Wf` +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Wf {} + | ++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/where-clause.rs b/tests/ui/impl-trait/in-trait/where-clause.rs new file mode 100644 index 000000000..87bac519c --- /dev/null +++ b/tests/ui/impl-trait/in-trait/where-clause.rs @@ -0,0 +1,24 @@ +// check-pass +// edition: 2021 + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::fmt::Debug; + +trait Foo { + fn foo<'a>(&'a self) -> impl Debug + where + Item: 'a; +} + +impl Foo for D { + fn foo<'a>(&'a self) -> impl Debug + where + Item: 'a, + { + self.clone() + } +} + +fn main() {} -- cgit v1.2.3