summaryrefslogtreecommitdiffstats
path: root/tests/ui/impl-trait
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/impl-trait')
-rw-r--r--tests/ui/impl-trait/arg-position-impl-trait-too-long.rs22
-rw-r--r--tests/ui/impl-trait/arg-position-impl-trait-too-long.stderr22
-rw-r--r--tests/ui/impl-trait/auto-trait-leak.stderr4
-rw-r--r--tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.rs2
-rw-r--r--tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr110
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.fixed19
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.rs19
-rw-r--r--tests/ui/impl-trait/extra-impl-in-trait-impl.stderr26
-rw-r--r--tests/ui/impl-trait/in-assoc-type-unconstrained.rs27
-rw-r--r--tests/ui/impl-trait/in-assoc-type-unconstrained.stderr59
-rw-r--r--tests/ui/impl-trait/in-assoc-type.rs21
-rw-r--r--tests/ui/impl-trait/in-assoc-type.stderr22
-rw-r--r--tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs4
-rw-r--r--tests/ui/impl-trait/in-trait/box-coerce-span-in-default.current.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/box-coerce-span-in-default.next.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/box-coerce-span-in-default.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-binder-shifting.current.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-binder-shifting.next.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-binder-shifting.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-constraint.current.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-constraint.next.stderr11
-rw-r--r--tests/ui/impl-trait/in-trait/default-method-constraint.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.current.stderr13
-rw-r--r--tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.next.stderr13
-rw-r--r--tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/foreign-dyn-error.rs8
-rw-r--r--tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr15
-rw-r--r--tests/ui/impl-trait/in-trait/foreign.rs9
-rw-r--r--tests/ui/impl-trait/in-trait/object-safety.current.stderr3
-rw-r--r--tests/ui/impl-trait/in-trait/object-safety.next.stderr3
-rw-r--r--tests/ui/impl-trait/issue-103181-1.current.stderr (renamed from tests/ui/impl-trait/issue-103181-1.stderr)2
-rw-r--r--tests/ui/impl-trait/issue-103181-1.next.stderr12
-rw-r--r--tests/ui/impl-trait/issue-103181-1.rs2
-rw-r--r--tests/ui/impl-trait/issue-108591.rs30
-rw-r--r--tests/ui/impl-trait/issue-108592.rs21
-rw-r--r--tests/ui/impl-trait/issue-36792.rs7
-rw-r--r--tests/ui/impl-trait/issues/issue-86800.rs10
-rw-r--r--tests/ui/impl-trait/issues/issue-86800.stderr14
-rw-r--r--tests/ui/impl-trait/multiple-defining-usages-in-body.rs12
-rw-r--r--tests/ui/impl-trait/multiple-defining-usages-in-body.stderr26
-rw-r--r--tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs4
-rw-r--r--tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr108
-rw-r--r--tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr5
-rw-r--r--tests/ui/impl-trait/wf-eval-order.rs4
44 files changed, 484 insertions, 264 deletions
diff --git a/tests/ui/impl-trait/arg-position-impl-trait-too-long.rs b/tests/ui/impl-trait/arg-position-impl-trait-too-long.rs
new file mode 100644
index 000000000..8ef9281c9
--- /dev/null
+++ b/tests/ui/impl-trait/arg-position-impl-trait-too-long.rs
@@ -0,0 +1,22 @@
+struct Header;
+struct EntryMetadata;
+struct Entry<A, B>(A, B);
+
+trait Tr {
+ type EncodedKey;
+ type EncodedValue;
+}
+
+fn test<C: Tr, R>(
+ // This APIT is long, however we shouldn't render the type name with a newline in it.
+ y: impl FnOnce(
+ &mut Header,
+ &mut [EntryMetadata],
+ &mut [Entry<C::EncodedKey, C::EncodedValue>]
+ ) -> R,
+) {
+ let () = y;
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/arg-position-impl-trait-too-long.stderr b/tests/ui/impl-trait/arg-position-impl-trait-too-long.stderr
new file mode 100644
index 000000000..40446a3d3
--- /dev/null
+++ b/tests/ui/impl-trait/arg-position-impl-trait-too-long.stderr
@@ -0,0 +1,22 @@
+error[E0308]: mismatched types
+ --> $DIR/arg-position-impl-trait-too-long.rs:18:9
+ |
+LL | y: impl FnOnce(
+ | ________-
+LL | | &mut Header,
+LL | | &mut [EntryMetadata],
+LL | | &mut [Entry<C::EncodedKey, C::EncodedValue>]
+LL | | ) -> R,
+ | |__________- this type parameter
+LL | ) {
+LL | let () = y;
+ | ^^ - this expression has type `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`
+ | |
+ | expected type parameter `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`, found `()`
+ |
+ = note: expected type parameter `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`
+ 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/auto-trait-leak.stderr b/tests/ui/impl-trait/auto-trait-leak.stderr
index e6c750d0e..aa4ee75bb 100644
--- a/tests/ui/impl-trait/auto-trait-leak.stderr
+++ b/tests/ui/impl-trait/auto-trait-leak.stderr
@@ -9,7 +9,7 @@ note: ...which requires borrow-checking `cycle1`...
|
LL | fn cycle1() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing MIR for `cycle1`...
+note: ...which requires promoting constants in MIR for `cycle1`...
--> $DIR/auto-trait-leak.rs:12:1
|
LL | fn cycle1() -> impl Clone {
@@ -55,7 +55,7 @@ note: ...which requires borrow-checking `cycle2`...
|
LL | fn cycle2() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing MIR for `cycle2`...
+note: ...which requires promoting constants in MIR for `cycle2`...
--> $DIR/auto-trait-leak.rs:19:1
|
LL | fn cycle2() -> impl Clone {
diff --git a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.rs b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.rs
index cbf1daabe..af368203d 100644
--- a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.rs
+++ b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.rs
@@ -26,7 +26,7 @@ fn bax() -> dyn Trait { //~ ERROR E0746
if true {
Struct
} else {
- 42 //~ ERROR `if` and `else` have incompatible types
+ 42
}
}
fn bam() -> Box<dyn Trait> {
diff --git a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
index dc1e40ea5..ed9261d0d 100644
--- a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
+++ b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
@@ -46,11 +46,10 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bap() -> Trait { Struct }
| ^^^^^ doesn't have a size known at compile-time
|
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
-help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | fn bap() -> impl Trait { Struct }
- | ~~~~~~~~~~
+LL | fn bap() -> Box<Trait> { Box::new(Struct) }
+ | ++++ + +++++++++ +
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
@@ -58,11 +57,14 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn ban() -> dyn Trait { Struct }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
-help: use `impl Trait` as the return type, as all return paths are of type `Struct`, which implements `Trait`
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
LL | fn ban() -> impl Trait { Struct }
- | ~~~~~~~~~~
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
+ |
+LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
+ | ++++ + +++++++++ +
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
@@ -70,14 +72,14 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bak() -> dyn Trait { unimplemented!() }
| ^^^^^^^^^ doesn't have a size known at compile-time
|
-help: use `impl Trait` as the return type if all return paths have the same type but you want to expose only the trait in the signature
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
LL | fn bak() -> impl Trait { unimplemented!() }
- | ~~~~~~~~~~
-help: use a boxed trait object if all return paths implement trait `Trait`
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | fn bak() -> Box<dyn Trait> { unimplemented!() }
- | ++++ +
+LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
+ | ++++ + +++++++++ +
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
@@ -85,34 +87,18 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bal() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
- = note: if all the returned values were of the same type you could use `impl Trait` as the return type
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
- = note: you can create a new `enum` with a variant for each returned type
-help: return a boxed trait object instead
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
-LL | fn bal() -> Box<dyn Trait> {
- | ++++ +
-help: ... and box this value
+LL | fn bal() -> impl Trait {
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | return Box::new(Struct);
- | +++++++++ +
-help: ... and box this value
+LL ~ fn bal() -> Box<dyn Trait> {
+LL | if true {
+LL ~ return Box::new(Struct);
+LL | }
+LL ~ Box::new(42)
|
-LL | Box::new(42)
- | +++++++++ +
-
-error[E0308]: `if` and `else` have incompatible types
- --> $DIR/dyn-trait-return-should-be-impl-trait.rs:29:9
- |
-LL | / if true {
-LL | | Struct
- | | ------ expected because of this
-LL | | } else {
-LL | | 42
- | | ^^ expected `Struct`, found integer
-LL | | }
- | |_____- `if` and `else` have incompatible types
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:25:13
@@ -120,22 +106,18 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bax() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
- = note: if all the returned values were of the same type you could use `impl Trait` as the return type
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
- = note: you can create a new `enum` with a variant for each returned type
-help: return a boxed trait object instead
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
-LL | fn bax() -> Box<dyn Trait> {
- | ++++ +
-help: ... and box this value
+LL | fn bax() -> impl Trait {
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | Box::new(Struct)
- | +++++++++ +
-help: ... and box this value
+LL ~ fn bax() -> Box<dyn Trait> {
+LL | if true {
+LL ~ Box::new(Struct)
+LL | } else {
+LL ~ Box::new(42)
|
-LL | Box::new(42)
- | +++++++++ +
error[E0308]: mismatched types
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:34:16
@@ -279,11 +261,18 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bat() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
-help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
LL | fn bat() -> impl Trait {
- | ~~~~~~~~~~
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
+ |
+LL ~ fn bat() -> Box<dyn Trait> {
+LL | if true {
+LL ~ return Box::new(0);
+LL | }
+LL ~ Box::new(42)
+ |
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:66:13
@@ -291,13 +280,20 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn bay() -> dyn Trait {
| ^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
-help: use `impl Trait` as the return type, as all return paths are of type `{integer}`, which implements `Trait`
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
LL | fn bay() -> impl Trait {
- | ~~~~~~~~~~
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
+ |
+LL ~ fn bay() -> Box<dyn Trait> {
+LL | if true {
+LL ~ Box::new(0)
+LL | } else {
+LL ~ Box::new(42)
+ |
-error: aborting due to 20 previous errors
+error: aborting due to 19 previous errors
Some errors have detailed explanations: E0277, E0308, E0746.
For more information about an error, try `rustc --explain E0277`.
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
new file mode 100644
index 000000000..cd4f2610d
--- /dev/null
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.fixed
@@ -0,0 +1,19 @@
+// run-rustfix
+
+struct S<T>(T);
+struct S2;
+
+impl<T: Default> Default for S<T> {
+ //~^ ERROR: unexpected `impl` keyword
+ //~| HELP: remove the extra `impl`
+ fn default() -> Self { todo!() }
+}
+
+impl Default for S2 {
+ //~^ ERROR: unexpected `impl` keyword
+ //~| HELP: remove the extra `impl`
+ fn default() -> Self { todo!() }
+}
+
+
+fn main() {}
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.rs b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs
new file mode 100644
index 000000000..024b703e6
--- /dev/null
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.rs
@@ -0,0 +1,19 @@
+// run-rustfix
+
+struct S<T>(T);
+struct S2;
+
+impl<T: Default> impl Default for S<T> {
+ //~^ ERROR: unexpected `impl` keyword
+ //~| HELP: remove the extra `impl`
+ fn default() -> Self { todo!() }
+}
+
+impl impl Default for S2 {
+ //~^ ERROR: unexpected `impl` keyword
+ //~| HELP: remove the extra `impl`
+ fn default() -> Self { todo!() }
+}
+
+
+fn main() {}
diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
new file mode 100644
index 000000000..5aafc8b64
--- /dev/null
+++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr
@@ -0,0 +1,26 @@
+error: unexpected `impl` keyword
+ --> $DIR/extra-impl-in-trait-impl.rs:6:18
+ |
+LL | impl<T: Default> impl Default for S<T> {
+ | ^^^^^ help: remove the extra `impl`
+ |
+note: this is parsed as an `impl Trait` type, but a trait is expected at this position
+ --> $DIR/extra-impl-in-trait-impl.rs:6:18
+ |
+LL | impl<T: Default> impl Default for S<T> {
+ | ^^^^^^^^^^^^
+
+error: unexpected `impl` keyword
+ --> $DIR/extra-impl-in-trait-impl.rs:12:6
+ |
+LL | impl impl Default for S2 {
+ | ^^^^^ help: remove the extra `impl`
+ |
+note: this is parsed as an `impl Trait` type, but a trait is expected at this position
+ --> $DIR/extra-impl-in-trait-impl.rs:12:6
+ |
+LL | impl impl Default for S2 {
+ | ^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/impl-trait/in-assoc-type-unconstrained.rs b/tests/ui/impl-trait/in-assoc-type-unconstrained.rs
new file mode 100644
index 000000000..c395b4195
--- /dev/null
+++ b/tests/ui/impl-trait/in-assoc-type-unconstrained.rs
@@ -0,0 +1,27 @@
+#![feature(impl_trait_in_assoc_type)]
+
+mod compare_ty {
+ trait Trait {
+ type Ty: IntoIterator<Item = ()>;
+ }
+ impl Trait for () {
+ type Ty = Option<impl Sized>;
+ //~^ ERROR: unconstrained opaque type
+ //~| ERROR: type mismatch resolving `<Option<<() as Trait>::Ty::{opaque#0}> as IntoIterator>::Item == ()`
+ }
+}
+
+mod compare_method {
+ trait Trait {
+ type Ty;
+ fn method() -> Self::Ty;
+ }
+ impl Trait for () {
+ type Ty = impl Sized;
+ //~^ ERROR: unconstrained opaque type
+ fn method() -> () {}
+ //~^ ERROR: method `method` has an incompatible type for trait
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr
new file mode 100644
index 000000000..1097cd0f4
--- /dev/null
+++ b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr
@@ -0,0 +1,59 @@
+error[E0271]: type mismatch resolving `<Option<<() as Trait>::Ty::{opaque#0}> as IntoIterator>::Item == ()`
+ --> $DIR/in-assoc-type-unconstrained.rs:8:19
+ |
+LL | type Ty = Option<impl Sized>;
+ | ^^^^^^^^^^^^^^^^^^ expected `()`, found opaque type
+ |
+ = note: expected unit type `()`
+ found opaque type `<() as compare_ty::Trait>::Ty::{opaque#0}`
+note: required by a bound in `compare_ty::Trait::Ty`
+ --> $DIR/in-assoc-type-unconstrained.rs:5:31
+ |
+LL | type Ty: IntoIterator<Item = ()>;
+ | ^^^^^^^^^ required by this bound in `Trait::Ty`
+
+error: unconstrained opaque type
+ --> $DIR/in-assoc-type-unconstrained.rs:8:26
+ |
+LL | type Ty = Option<impl Sized>;
+ | ^^^^^^^^^^
+ |
+ = note: `Ty` must be used in combination with a concrete type within the same impl
+
+error[E0053]: method `method` has an incompatible type for trait
+ --> $DIR/in-assoc-type-unconstrained.rs:22:24
+ |
+LL | type Ty = impl Sized;
+ | ---------- the expected opaque type
+LL |
+LL | fn method() -> () {}
+ | ^^
+ | |
+ | expected opaque type, found `()`
+ | help: change the output type to match the trait: `<() as compare_method::Trait>::Ty`
+ |
+note: type in trait
+ --> $DIR/in-assoc-type-unconstrained.rs:17:24
+ |
+LL | fn method() -> Self::Ty;
+ | ^^^^^^^^
+ = note: expected signature `fn() -> <() as compare_method::Trait>::Ty`
+ found signature `fn()`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/in-assoc-type-unconstrained.rs:22:9
+ |
+LL | fn method() -> () {}
+ | ^^^^^^^^^^^^^^^^^
+
+error: unconstrained opaque type
+ --> $DIR/in-assoc-type-unconstrained.rs:20:19
+ |
+LL | type Ty = impl Sized;
+ | ^^^^^^^^^^
+ |
+ = note: `Ty` must be used in combination with a concrete type within the same impl
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0053, E0271.
+For more information about an error, try `rustc --explain E0053`.
diff --git a/tests/ui/impl-trait/in-assoc-type.rs b/tests/ui/impl-trait/in-assoc-type.rs
new file mode 100644
index 000000000..36c54bdd6
--- /dev/null
+++ b/tests/ui/impl-trait/in-assoc-type.rs
@@ -0,0 +1,21 @@
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo<T> {
+ type Bar;
+ fn foo(&self) -> <Self as Foo<()>>::Bar
+ where
+ Self: Foo<()>;
+}
+
+impl Foo<()> for () {
+ type Bar = impl std::fmt::Debug;
+ fn foo(&self) -> Self::Bar {}
+}
+
+impl Foo<i32> for () {
+ type Bar = u32;
+ fn foo(&self) -> <Self as Foo<()>>::Bar {}
+ //~^ ERROR: mismatched types
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-assoc-type.stderr b/tests/ui/impl-trait/in-assoc-type.stderr
new file mode 100644
index 000000000..f0a272dc2
--- /dev/null
+++ b/tests/ui/impl-trait/in-assoc-type.stderr
@@ -0,0 +1,22 @@
+error[E0308]: mismatched types
+ --> $DIR/in-assoc-type.rs:17:22
+ |
+LL | type Bar = impl std::fmt::Debug;
+ | -------------------- the expected opaque type
+...
+LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
+ | --- ^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found `()`
+ | |
+ | implicitly returns `()` as its body has no tail or `return` expression
+ |
+ = note: expected opaque type `<() as Foo<()>>::Bar`
+ found unit type `()`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/in-assoc-type.rs:17:5
+ |
+LL | fn foo(&self) -> <Self as Foo<()>>::Bar {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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/auxiliary/rpitit.rs b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
index ffeabe5c2..776006124 100644
--- a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
+++ b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs
@@ -5,10 +5,10 @@
use std::ops::Deref;
pub trait Foo {
- fn bar() -> impl Deref<Target = impl Sized>;
+ fn bar(self) -> impl Deref<Target = impl Sized>;
}
pub struct Foreign;
impl Foo for Foreign {
- fn bar() -> &'static () { &() }
+ fn bar(self) -> &'static () { &() }
}
diff --git a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.current.stderr b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.current.stderr
deleted file mode 100644
index 05c025cc1..000000000
--- a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.current.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-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:5:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.next.stderr b/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.next.stderr
deleted file mode 100644
index 05c025cc1..000000000
--- a/tests/ui/impl-trait/in-trait/box-coerce-span-in-default.next.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-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:5:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
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
index 163bb4fcf..f5290a5f4 100644
--- 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
@@ -3,7 +3,6 @@
// revisions: current next
#![feature(return_position_impl_trait_in_trait)]
-//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete
struct TestA {}
struct TestB {}
diff --git a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.current.stderr b/tests/ui/impl-trait/in-trait/default-method-binder-shifting.current.stderr
deleted file mode 100644
index a0c0589b9..000000000
--- a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.current.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/default-method-binder-shifting.rs:5:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.next.stderr b/tests/ui/impl-trait/in-trait/default-method-binder-shifting.next.stderr
deleted file mode 100644
index a0c0589b9..000000000
--- a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.next.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/default-method-binder-shifting.rs:5:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.rs b/tests/ui/impl-trait/in-trait/default-method-binder-shifting.rs
index de82544f2..187039f44 100644
--- a/tests/ui/impl-trait/in-trait/default-method-binder-shifting.rs
+++ b/tests/ui/impl-trait/in-trait/default-method-binder-shifting.rs
@@ -3,7 +3,6 @@
// revisions: current next
#![feature(return_position_impl_trait_in_trait)]
-//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete
trait Trait {
type Type;
diff --git a/tests/ui/impl-trait/in-trait/default-method-constraint.current.stderr b/tests/ui/impl-trait/in-trait/default-method-constraint.current.stderr
deleted file mode 100644
index 7bb79911f..000000000
--- a/tests/ui/impl-trait/in-trait/default-method-constraint.current.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/default-method-constraint.rs:7:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/impl-trait/in-trait/default-method-constraint.next.stderr b/tests/ui/impl-trait/in-trait/default-method-constraint.next.stderr
deleted file mode 100644
index 7bb79911f..000000000
--- a/tests/ui/impl-trait/in-trait/default-method-constraint.next.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/default-method-constraint.rs:7:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/impl-trait/in-trait/default-method-constraint.rs b/tests/ui/impl-trait/in-trait/default-method-constraint.rs
index e85fe3c86..4f0bf2e7d 100644
--- a/tests/ui/impl-trait/in-trait/default-method-constraint.rs
+++ b/tests/ui/impl-trait/in-trait/default-method-constraint.rs
@@ -5,7 +5,6 @@
// This didn't work in the previous default RPITIT method hack attempt
#![feature(return_position_impl_trait_in_trait)]
-//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete
trait Foo {
fn bar(x: bool) -> impl Sized {
diff --git a/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.current.stderr b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.current.stderr
index b8a793e1a..d4d0124a6 100644
--- a/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.current.stderr
+++ b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.current.stderr
@@ -1,14 +1,5 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/dont-project-to-rpitit-with-no-value.rs:4:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
error[E0046]: not all trait items implemented, missing: `foo`
- --> $DIR/dont-project-to-rpitit-with-no-value.rs:12:1
+ --> $DIR/dont-project-to-rpitit-with-no-value.rs:11:1
|
LL | fn foo(&self) -> impl Sized;
| ---------------------------- `foo` from trait
@@ -16,6 +7,6 @@ LL | fn foo(&self) -> impl Sized;
LL | impl MyTrait for i32 {
| ^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
-error: aborting due to previous error; 1 warning emitted
+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/dont-project-to-rpitit-with-no-value.next.stderr b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.next.stderr
index b8a793e1a..d4d0124a6 100644
--- a/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.next.stderr
+++ b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.next.stderr
@@ -1,14 +1,5 @@
-warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
- --> $DIR/dont-project-to-rpitit-with-no-value.rs:4:12
- |
-LL | #![feature(return_position_impl_trait_in_trait)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = note: `#[warn(incomplete_features)]` on by default
-
error[E0046]: not all trait items implemented, missing: `foo`
- --> $DIR/dont-project-to-rpitit-with-no-value.rs:12:1
+ --> $DIR/dont-project-to-rpitit-with-no-value.rs:11:1
|
LL | fn foo(&self) -> impl Sized;
| ---------------------------- `foo` from trait
@@ -16,6 +7,6 @@ LL | fn foo(&self) -> impl Sized;
LL | impl MyTrait for i32 {
| ^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
-error: aborting due to previous error; 1 warning emitted
+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/dont-project-to-rpitit-with-no-value.rs b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.rs
index 8329ce1f8..4d50b8c92 100644
--- a/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.rs
+++ b/tests/ui/impl-trait/in-trait/dont-project-to-rpitit-with-no-value.rs
@@ -2,7 +2,6 @@
// revisions: current next
#![feature(return_position_impl_trait_in_trait)]
-//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete
trait MyTrait {
fn foo(&self) -> impl Sized;
diff --git a/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs b/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
new file mode 100644
index 000000000..ecb5e62c4
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
@@ -0,0 +1,8 @@
+// aux-build: rpitit.rs
+
+extern crate rpitit;
+
+fn main() {
+ let _: &dyn rpitit::Foo = todo!();
+ //~^ ERROR the trait `Foo` cannot be made into an object
+}
diff --git a/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr b/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
new file mode 100644
index 000000000..6eef392c0
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
@@ -0,0 +1,15 @@
+error[E0038]: the trait `Foo` cannot be made into an object
+ --> $DIR/foreign-dyn-error.rs:6:12
+ |
+LL | let _: &dyn rpitit::Foo = todo!();
+ | ^^^^^^^^^^^^^^^^ `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/auxiliary/rpitit.rs:8:21
+ |
+LL | fn bar(self) -> impl Deref<Target = impl Sized>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because method `bar` references an `impl Trait` type in its return type
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0038`.
diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs
index f4972d948..98417b343 100644
--- a/tests/ui/impl-trait/in-trait/foreign.rs
+++ b/tests/ui/impl-trait/in-trait/foreign.rs
@@ -5,17 +5,18 @@
extern crate rpitit;
+use rpitit::{Foo, Foreign};
use std::sync::Arc;
// Implement an RPITIT from another crate.
struct Local;
-impl rpitit::Foo for Local {
- fn bar() -> Arc<String> { Arc::new(String::new()) }
+impl Foo for Local {
+ fn bar(self) -> Arc<String> { Arc::new(String::new()) }
}
fn main() {
// Witness an RPITIT from another crate.
- let &() = <rpitit::Foreign as rpitit::Foo>::bar();
+ let &() = Foreign.bar();
- let x: Arc<String> = <Local as rpitit::Foo>::bar();
+ let x: Arc<String> = Local.bar();
}
diff --git a/tests/ui/impl-trait/in-trait/object-safety.current.stderr b/tests/ui/impl-trait/in-trait/object-safety.current.stderr
index b7f2b019a..2c340a023 100644
--- a/tests/ui/impl-trait/in-trait/object-safety.current.stderr
+++ b/tests/ui/impl-trait/in-trait/object-safety.current.stderr
@@ -42,8 +42,7 @@ LL | trait Foo {
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>`
+ = note: required for the cast from `Box<u32>` to `Box<dyn Foo>`
error: aborting due to 3 previous errors
diff --git a/tests/ui/impl-trait/in-trait/object-safety.next.stderr b/tests/ui/impl-trait/in-trait/object-safety.next.stderr
index b7f2b019a..2c340a023 100644
--- a/tests/ui/impl-trait/in-trait/object-safety.next.stderr
+++ b/tests/ui/impl-trait/in-trait/object-safety.next.stderr
@@ -42,8 +42,7 @@ LL | trait Foo {
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>`
+ = note: required for the cast from `Box<u32>` to `Box<dyn Foo>`
error: aborting due to 3 previous errors
diff --git a/tests/ui/impl-trait/issue-103181-1.stderr b/tests/ui/impl-trait/issue-103181-1.current.stderr
index cd026607d..e87a9d28a 100644
--- a/tests/ui/impl-trait/issue-103181-1.stderr
+++ b/tests/ui/impl-trait/issue-103181-1.current.stderr
@@ -1,5 +1,5 @@
error[E0046]: not all trait items implemented, missing: `Error`
- --> $DIR/issue-103181-1.rs:9:5
+ --> $DIR/issue-103181-1.rs:11:5
|
LL | type Error;
| ---------- `Error` from trait
diff --git a/tests/ui/impl-trait/issue-103181-1.next.stderr b/tests/ui/impl-trait/issue-103181-1.next.stderr
new file mode 100644
index 000000000..e87a9d28a
--- /dev/null
+++ b/tests/ui/impl-trait/issue-103181-1.next.stderr
@@ -0,0 +1,12 @@
+error[E0046]: not all trait items implemented, missing: `Error`
+ --> $DIR/issue-103181-1.rs:11:5
+ |
+LL | type Error;
+ | ---------- `Error` from trait
+LL | }
+LL | impl HttpBody for () {
+ | ^^^^^^^^^^^^^^^^^^^^ missing `Error` 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/issue-103181-1.rs b/tests/ui/impl-trait/issue-103181-1.rs
index 197aedf9d..5154abcd6 100644
--- a/tests/ui/impl-trait/issue-103181-1.rs
+++ b/tests/ui/impl-trait/issue-103181-1.rs
@@ -1,3 +1,5 @@
+// revisions: current next
+//[next] compile-flags: -Ztrait-solver=next
// edition:2021
mod hyper {
diff --git a/tests/ui/impl-trait/issue-108591.rs b/tests/ui/impl-trait/issue-108591.rs
new file mode 100644
index 000000000..6b9d14941
--- /dev/null
+++ b/tests/ui/impl-trait/issue-108591.rs
@@ -0,0 +1,30 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+struct MyTy<'a>(Vec<u8>, &'a ());
+
+impl MyTy<'_> {
+ fn one(&mut self) -> &mut impl Sized {
+ &mut self.0
+ }
+ fn two(&mut self) -> &mut (impl Sized + 'static) {
+ self.one()
+ }
+}
+
+type Opaque<'a> = impl Sized;
+fn define<'a>() -> Opaque<'a> {}
+
+fn test<'a>() {
+ None::<&'static Opaque<'a>>;
+}
+
+fn one<'a, 'b: 'b>() -> &'a impl Sized {
+ &()
+}
+fn two<'a, 'b>() {
+ one::<'a, 'b>();
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs
new file mode 100644
index 000000000..58a0ed9bf
--- /dev/null
+++ b/tests/ui/impl-trait/issue-108592.rs
@@ -0,0 +1,21 @@
+// check-pass
+#![feature(type_alias_impl_trait)]
+
+fn opaque<'a: 'a>() -> impl Sized {}
+fn assert_static<T: 'static>(_: T) {}
+
+fn test_closure() {
+ let closure = |_| {
+ assert_static(opaque());
+ };
+ closure(&opaque());
+}
+
+type Opaque<'a> = impl Sized;
+fn define<'a>() -> Opaque<'a> {}
+
+fn test_tait(_: &Opaque<'_>) {
+ None::<&'static Opaque<'_>>;
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/issue-36792.rs b/tests/ui/impl-trait/issue-36792.rs
new file mode 100644
index 000000000..99ae633dd
--- /dev/null
+++ b/tests/ui/impl-trait/issue-36792.rs
@@ -0,0 +1,7 @@
+// run-pass
+fn foo() -> impl Copy {
+ foo
+}
+fn main() {
+ foo();
+}
diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs
index 351243c67..ec4fda322 100644
--- a/tests/ui/impl-trait/issues/issue-86800.rs
+++ b/tests/ui/impl-trait/issues/issue-86800.rs
@@ -1,14 +1,12 @@
#![feature(type_alias_impl_trait)]
// edition:2021
-// unset-rustc-env:RUST_BACKTRACE
// compile-flags:-Z treat-err-as-bug=1
-// error-pattern:stack backtrace:
+// error-pattern: aborting due to `-Z treat-err-as-bug=1`
// failure-status:101
-// normalize-stderr-test "note: .*" -> ""
-// normalize-stderr-test "thread 'rustc' .*" -> ""
-// normalize-stderr-test " +[0-9]+:.*\n" -> ""
-// normalize-stderr-test " +at .*\n" -> ""
+// normalize-stderr-test ".*note: .*\n\n" -> ""
+// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
+// rustc-env:RUST_BACKTRACE=0
use std::future::Future;
diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr
index f3a773837..facab390d 100644
--- a/tests/ui/impl-trait/issues/issue-86800.stderr
+++ b/tests/ui/impl-trait/issues/issue-86800.stderr
@@ -1,24 +1,12 @@
error: unconstrained opaque type
- --> $DIR/issue-86800.rs:33:34
+ --> $DIR/issue-86800.rs:31:34
|
LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- =
-
-
-stack backtrace:
-
error: the compiler unexpectedly panicked. this is a bug.
-
-
-
-
-
-
query stack during panic:
#0 [type_of] computing type of `TransactionFuture::{opaque#0}`
#1 [check_mod_item_types] checking item types in top-level module
-#2 [analysis] running analysis passes on this crate
end of query stack
diff --git a/tests/ui/impl-trait/multiple-defining-usages-in-body.rs b/tests/ui/impl-trait/multiple-defining-usages-in-body.rs
new file mode 100644
index 000000000..c3a6f09f8
--- /dev/null
+++ b/tests/ui/impl-trait/multiple-defining-usages-in-body.rs
@@ -0,0 +1,12 @@
+trait Trait {}
+impl Trait for () {}
+
+fn foo<T: Trait, U: Trait>() -> impl Trait {
+ //~^ WARN function cannot return without recursing [unconditional_recursion]
+ let a: T = foo::<T, U>();
+ //~^ ERROR concrete type differs from previous defining opaque type use
+ loop {}
+ let _: T = foo::<U, T>();
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr b/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr
new file mode 100644
index 000000000..06991749b
--- /dev/null
+++ b/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr
@@ -0,0 +1,26 @@
+warning: function cannot return without recursing
+ --> $DIR/multiple-defining-usages-in-body.rs:4:1
+ |
+LL | fn foo<T: Trait, U: Trait>() -> impl Trait {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
+LL |
+LL | let a: T = foo::<T, U>();
+ | ------------- recursive call site
+ |
+ = help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
+
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/multiple-defining-usages-in-body.rs:6:16
+ |
+LL | let a: T = foo::<T, U>();
+ | ^^^^^^^^^^^^^ expected `U`, got `T`
+ |
+note: previous use here
+ --> $DIR/multiple-defining-usages-in-body.rs:9:16
+ |
+LL | let _: T = foo::<U, T>();
+ | ^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
diff --git a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
index fa7664a83..a8a6288eb 100644
--- a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
+++ b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
@@ -77,7 +77,7 @@ fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed
fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
match 13 {
0 => 0i32,
- 1 => 1u32, //~ ERROR `match` arms have incompatible types
+ 1 => 1u32,
_ => 2u32,
}
}
@@ -86,7 +86,7 @@ fn man() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed
if false {
0i32
} else {
- 1u32 //~ ERROR `if` and `else` have incompatible types
+ 1u32
}
}
diff --git a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
index 3c65fd998..9205d7450 100644
--- a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
+++ b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
@@ -171,39 +171,20 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn hat() -> dyn std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
- = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
- = note: you can create a new `enum` with a variant for each returned type
-help: return a boxed trait object instead
- |
-LL | fn hat() -> Box<dyn std::fmt::Display> {
- | ++++ +
-help: ... and box this value
- |
-LL | return Box::new(0i32);
- | +++++++++ +
-help: ... and box this value
- |
-LL | Box::new(1u32)
- | +++++++++ +
-
-error[E0308]: `match` arms have incompatible types
- --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:80:14
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
-LL | / match 13 {
-LL | | 0 => 0i32,
- | | ---- this is found to be of type `i32`
-LL | | 1 => 1u32,
- | | ^^^^ expected `i32`, found `u32`
-LL | | _ => 2u32,
-LL | | }
- | |_____- `match` arms have incompatible types
+LL | fn hat() -> impl std::fmt::Display {
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-help: change the type of the numeric literal from `u32` to `i32`
+LL ~ fn hat() -> Box<dyn std::fmt::Display> {
+LL | match 13 {
+LL | 0 => {
+LL ~ return Box::new(0i32);
+LL | }
+LL | _ => {
+LL ~ Box::new(1u32)
|
-LL | 1 => 1i32,
- | ~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:77:13
@@ -211,43 +192,18 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn pug() -> dyn std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
- = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
- = note: you can create a new `enum` with a variant for each returned type
-help: return a boxed trait object instead
- |
-LL | fn pug() -> Box<dyn std::fmt::Display> {
- | ++++ +
-help: ... and box this value
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
-LL | 0 => Box::new(0i32),
- | +++++++++ +
-help: ... and box this value
- |
-LL | 1 => Box::new(1u32),
- | +++++++++ +
-help: ... and box this value
- |
-LL | _ => Box::new(2u32),
- | +++++++++ +
-
-error[E0308]: `if` and `else` have incompatible types
- --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:89:9
+LL | fn pug() -> impl std::fmt::Display {
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | / if false {
-LL | | 0i32
- | | ---- expected because of this
-LL | | } else {
-LL | | 1u32
- | | ^^^^ expected `i32`, found `u32`
-LL | | }
- | |_____- `if` and `else` have incompatible types
- |
-help: change the type of the numeric literal from `u32` to `i32`
+LL ~ fn pug() -> Box<dyn std::fmt::Display> {
+LL | match 13 {
+LL ~ 0 => Box::new(0i32),
+LL ~ 1 => Box::new(1u32),
+LL ~ _ => Box::new(2u32),
|
-LL | 1i32
- | ~~~
error[E0746]: return type cannot have an unboxed trait object
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:85:13
@@ -255,24 +211,20 @@ error[E0746]: return type cannot have an unboxed trait object
LL | fn man() -> dyn std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
- = note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
- = note: you can create a new `enum` with a variant for each returned type
-help: return a boxed trait object instead
+help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type
|
-LL | fn man() -> Box<dyn std::fmt::Display> {
- | ++++ +
-help: ... and box this value
+LL | fn man() -> impl std::fmt::Display {
+ | ~~~~
+help: box the return type, and wrap all of the returned values in `Box::new`
|
-LL | Box::new(0i32)
- | +++++++++ +
-help: ... and box this value
+LL ~ fn man() -> Box<dyn std::fmt::Display> {
+LL | if false {
+LL ~ Box::new(0i32)
+LL | } else {
+LL ~ Box::new(1u32)
|
-LL | Box::new(1u32)
- | +++++++++ +
-error: aborting due to 14 previous errors
+error: aborting due to 12 previous errors
Some errors have detailed explanations: E0308, E0746.
For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
index f7aff4195..fe62a8f32 100644
--- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
+++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr
@@ -43,6 +43,11 @@ LL | fn eq(&self, _other: &(Bar, i32)) -> bool {
|
= note: expected signature `fn(&b::Bar, &(b::Foo, i32)) -> _`
found signature `fn(&b::Bar, &(b::Bar, i32)) -> _`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:9
+ |
+LL | fn eq(&self, _other: &(Bar, i32)) -> bool {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
diff --git a/tests/ui/impl-trait/wf-eval-order.rs b/tests/ui/impl-trait/wf-eval-order.rs
index c7d6bb870..8638fc2e7 100644
--- a/tests/ui/impl-trait/wf-eval-order.rs
+++ b/tests/ui/impl-trait/wf-eval-order.rs
@@ -31,9 +31,9 @@ fn main() {
//
// - `wf(typeof(x))` because we use a projection candidate.
// - `<i32 as B>::V: Clone` because that's a bound on the trait.
- // - `<i32 as B>::V` normalizes to `_#1` where `<i32 as A>::U == _#1`
+ // - `<i32 as B>::V` normalizes to `?1t` where `<i32 as A>::U == ?1t`
//
- // This all works if we evaluate `<i32 as A>::U == _#1` before
+ // This all works if we evaluate `<i32 as A>::U == ?1t` before
// `<i32 as B>::V`, but we previously had the opposite order.
let x = hide(X(0));
}