summaryrefslogtreecommitdiffstats
path: root/src/test/ui/impl-trait/in-trait
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs11
-rw-r--r--src/test/ui/impl-trait/in-trait/deep-match-works.rs16
-rw-r--r--src/test/ui/impl-trait/in-trait/deep-match.rs15
-rw-r--r--src/test/ui/impl-trait/in-trait/deep-match.stderr15
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs13
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr11
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err.rs13
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err.stderr12
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/doesnt-satisfy.rs13
-rw-r--r--src/test/ui/impl-trait/in-trait/doesnt-satisfy.stderr17
-rw-r--r--src/test/ui/impl-trait/in-trait/early.rs23
-rw-r--r--src/test/ui/impl-trait/in-trait/encode.rs9
-rw-r--r--src/test/ui/impl-trait/in-trait/foreign.rs9
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102140.rs30
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102140.stderr29
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102301.rs18
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102571.rs24
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102571.stderr14
-rw-r--r--src/test/ui/impl-trait/in-trait/nested-rpitit.rs32
-rw-r--r--src/test/ui/impl-trait/in-trait/object-safety.rs22
-rw-r--r--src/test/ui/impl-trait/in-trait/object-safety.stderr50
-rw-r--r--src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs19
-rw-r--r--src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr17
-rw-r--r--src/test/ui/impl-trait/in-trait/opaque-in-impl.rs48
-rw-r--r--src/test/ui/impl-trait/in-trait/reveal.rs18
-rw-r--r--src/test/ui/impl-trait/in-trait/signature-mismatch.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/signature-mismatch.stderr16
-rw-r--r--src/test/ui/impl-trait/in-trait/success.rs40
-rw-r--r--src/test/ui/impl-trait/in-trait/wf-bounds.rs16
-rw-r--r--src/test/ui/impl-trait/in-trait/wf-bounds.stderr33
32 files changed, 666 insertions, 0 deletions
diff --git a/src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs
new file mode 100644
index 000000000..74df300f8
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/deep-match-works.rs b/src/test/ui/impl-trait/in-trait/deep-match-works.rs
new file mode 100644
index 000000000..772da845e
--- /dev/null
+++ b/src/test/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>(T);
+
+trait Foo {
+ fn bar() -> Wrapper<impl Sized>;
+}
+
+impl Foo for () {
+ fn bar() -> Wrapper<i32> { Wrapper(0) }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/deep-match.rs b/src/test/ui/impl-trait/in-trait/deep-match.rs
new file mode 100644
index 000000000..a6385147c
--- /dev/null
+++ b/src/test/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>(T);
+
+trait Foo {
+ fn bar() -> Wrapper<impl Sized>;
+}
+
+impl Foo for () {
+ fn bar() -> i32 { 0 }
+ //~^ ERROR method `bar` has an incompatible return type for trait
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/deep-match.stderr b/src/test/ui/impl-trait/in-trait/deep-match.stderr
new file mode 100644
index 000000000..034ee5ea4
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
new file mode 100644
index 000000000..45ae2b8ad
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr
new file mode 100644
index 000000000..142b1bff1
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/default-body-type-err.rs b/src/test/ui/impl-trait/in-trait/default-body-type-err.rs
new file mode 100644
index 000000000..ac9baf91c
--- /dev/null
+++ b/src/test/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<Target = String> {
+ //~^ type mismatch resolving `<&i32 as Deref>::Target == String`
+ &1i32
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/default-body-type-err.stderr b/src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
new file mode 100644
index 000000000..461247a3e
--- /dev/null
+++ b/src/test/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<Target = String> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs b/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs
new file mode 100644
index 000000000..ad3cc7c25
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/default-body.rs b/src/test/ui/impl-trait/in-trait/default-body.rs
new file mode 100644
index 000000000..b0baf5bb1
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/doesnt-satisfy.rs b/src/test/ui/impl-trait/in-trait/doesnt-satisfy.rs
new file mode 100644
index 000000000..bb4e0d44f
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/doesnt-satisfy.stderr b/src/test/ui/impl-trait/in-trait/doesnt-satisfy.stderr
new file mode 100644
index 000000000..aa5492d28
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/early.rs b/src/test/ui/impl-trait/in-trait/early.rs
new file mode 100644
index 000000000..9c1c2b503
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/encode.rs b/src/test/ui/impl-trait/in-trait/encode.rs
new file mode 100644
index 000000000..efb9f6498
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/foreign.rs b/src/test/ui/impl-trait/in-trait/foreign.rs
new file mode 100644
index 000000000..6341f5b42
--- /dev/null
+++ b/src/test/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 () = <rpitit::Foreign as rpitit::Foo>::bar();
+}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102140.rs b/src/test/ui/impl-trait/in-trait/issue-102140.rs
new file mode 100644
index 000000000..be1e012ac
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/issue-102140.stderr b/src/test/ui/impl-trait/in-trait/issue-102140.stderr
new file mode 100644
index 000000000..08602185f
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102140.stderr
@@ -0,0 +1,29 @@
+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`
+ | | help: consider removing the leading `&`-reference
+ | required by a bound introduced by this call
+
+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/src/test/ui/impl-trait/in-trait/issue-102301.rs b/src/test/ui/impl-trait/in-trait/issue-102301.rs
new file mode 100644
index 000000000..a93714a65
--- /dev/null
+++ b/src/test/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<T> {
+ fn foo<F2: Foo<T>>(self) -> impl Foo<T>;
+}
+
+struct Bar;
+
+impl Foo<u8> for Bar {
+ fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
+ self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102571.rs b/src/test/ui/impl-trait/in-trait/issue-102571.rs
new file mode 100644
index 000000000..61c91e644
--- /dev/null
+++ b/src/test/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<Target = impl Display + ?Sized>;
+}
+
+struct A;
+
+impl Foo for A {
+ fn bar(self) -> &'static str {
+ "Hello, world"
+ }
+}
+
+fn foo<T: Foo>(t: T) {
+ let () = t.bar();
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102571.stderr b/src/test/ui/impl-trait/in-trait/issue-102571.stderr
new file mode 100644
index 000000000..87219941d
--- /dev/null
+++ b/src/test/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<Target = impl std::fmt::Display + ?Sized>`
+ | |
+ | expected associated type, found `()`
+ |
+ = note: expected associated type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
+ found unit type `()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/impl-trait/in-trait/nested-rpitit.rs b/src/test/ui/impl-trait/in-trait/nested-rpitit.rs
new file mode 100644
index 000000000..65285e3a3
--- /dev/null
+++ b/src/test/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<Target = impl Display + ?Sized>;
+}
+
+struct A;
+
+impl Foo for A {
+ fn bar(self) -> &'static str {
+ "Hello, world"
+ }
+}
+
+struct B;
+
+impl Foo for B {
+ fn bar(self) -> Box<i32> {
+ Box::new(42)
+ }
+}
+
+fn main() {
+ println!("Message for you: {:?}", &*A.bar());
+ println!("Another for you: {:?}", &*B.bar());
+}
diff --git a/src/test/ui/impl-trait/in-trait/object-safety.rs b/src/test/ui/impl-trait/in-trait/object-safety.rs
new file mode 100644
index 000000000..dd35b9a2d
--- /dev/null
+++ b/src/test/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<dyn Foo>;
+ //~^ 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/src/test/ui/impl-trait/in-trait/object-safety.stderr b/src/test/ui/impl-trait/in-trait/object-safety.stderr
new file mode 100644
index 000000000..9a1554b5e
--- /dev/null
+++ b/src/test/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<dyn Foo>;
+ | ^^^^^^^^^^^^ `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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/object-safety.rs:7:8
+ |
+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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/object-safety.rs:7:8
+ |
+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<dyn Foo>;
+ | ^^^^^^^^^^^^^^^^ `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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/object-safety.rs:7:8
+ |
+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<u32>` to implement `CoerceUnsized<Box<dyn Foo>>`
+ = note: required by cast to type `Box<dyn Foo>`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0038`.
diff --git a/src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs b/src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.rs
new file mode 100644
index 000000000..3ac264e8e
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr b/src/test/ui/impl-trait/in-trait/opaque-in-impl-is-opaque.stderr
new file mode 100644
index 000000000..15edda483
--- /dev/null
+++ b/src/test/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/src/test/ui/impl-trait/in-trait/opaque-in-impl.rs b/src/test/ui/impl-trait/in-trait/opaque-in-impl.rs
new file mode 100644
index 000000000..2e0662969
--- /dev/null
+++ b/src/test/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<T: Default + Debug> Foo for std::marker::PhantomData<T> {
+ fn foo(&self) -> impl Debug {
+ T::default()
+ }
+}
+
+trait Bar {
+ fn bar<T>(&self) -> impl Debug;
+}
+
+impl Bar for () {
+ fn bar<T>(&self) -> impl Debug {
+ format!("Hello with generic {}", std::any::type_name::<T>())
+ }
+}
+
+trait Baz {
+ fn baz(&self) -> impl Debug + '_;
+}
+
+impl Baz for String {
+ fn baz(&self) -> impl Debug + '_ {
+ (self,)
+ }
+}
+
+fn main() {
+ println!("{:?}", ().foo());
+ println!("{:?}", ().bar::<u64>());
+ println!("{:?}", "hi".to_string().baz());
+}
diff --git a/src/test/ui/impl-trait/in-trait/reveal.rs b/src/test/ui/impl-trait/in-trait/reveal.rs
new file mode 100644
index 000000000..d6ede1cc4
--- /dev/null
+++ b/src/test/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 Sized>;
+}
+
+impl Foo for () {
+ fn f() -> Box<String> {
+ Box::new(String::new())
+ }
+}
+
+fn main() {
+ let x: Box<String> = <() as Foo>::f();
+}
diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.rs b/src/test/ui/impl-trait/in-trait/signature-mismatch.rs
new file mode 100644
index 000000000..90682631a
--- /dev/null
+++ b/src/test/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<Output = Vec<u8>>;
+}
+
+pub struct Struct;
+
+impl AsyncTrait for Struct {
+ fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
+ //~^ ERROR `impl` item signature doesn't match `trait` item signature
+ async move { buff.to_vec() }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr b/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr
new file mode 100644
index 000000000..6663d7faa
--- /dev/null
+++ b/src/test/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<Output = Vec<u8>>;
+ | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
+...
+LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
+ |
+ = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
+ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '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/src/test/ui/impl-trait/in-trait/success.rs b/src/test/ui/impl-trait/in-trait/success.rs
new file mode 100644
index 000000000..4cbe682b4
--- /dev/null
+++ b/src/test/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: Foo>(t: T) {
+ println!("{}", t.bar());
+}
+
+fn main() {
+ println!("{}", "Hello, world.".bar());
+ println!("The answer is {}!", 42.bar());
+ foo_generically(Yay);
+}
diff --git a/src/test/ui/impl-trait/in-trait/wf-bounds.rs b/src/test/ui/impl-trait/in-trait/wf-bounds.rs
new file mode 100644
index 000000000..2c71583b3
--- /dev/null
+++ b/src/test/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<T> {}
+
+trait Uwu {
+ fn nya() -> impl Wf<Vec<[u8]>>;
+ //~^ 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/src/test/ui/impl-trait/in-trait/wf-bounds.stderr b/src/test/ui/impl-trait/in-trait/wf-bounds.stderr
new file mode 100644
index 000000000..92e36841b
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/wf-bounds.stderr
@@ -0,0 +1,33 @@
+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<Vec<[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 `Vec`
+ --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
+ |
+LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
+ | ^ required by this bound in `Vec`
+
+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<T> {}
+ | ^ required by this bound in `Wf`
+help: consider relaxing the implicit `Sized` restriction
+ |
+LL | trait Wf<T: ?Sized> {}
+ | ++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.