summaryrefslogtreecommitdiffstats
path: root/tests/ui/type-alias-impl-trait
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/type-alias-impl-trait')
-rw-r--r--tests/ui/type-alias-impl-trait/auto-trait-leakage.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr52
-rw-r--r--tests/ui/type-alias-impl-trait/bound_reduction2.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/bound_reduction2.stderr16
-rw-r--r--tests/ui/type-alias-impl-trait/bounds-are-checked3.rs16
-rw-r--r--tests/ui/type-alias-impl-trait/bounds-are-checked3.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/bounds.rs16
-rw-r--r--tests/ui/type-alias-impl-trait/closure_args.rs11
-rw-r--r--tests/ui/type-alias-impl-trait/closure_args2.rs23
-rw-r--r--tests/ui/type-alias-impl-trait/coherence.stderr2
-rw-r--r--tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs25
-rw-r--r--tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.stderr12
-rw-r--r--tests/ui/type-alias-impl-trait/coherence_generalization.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/cross_inference.rs6
-rw-r--r--tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs12
-rw-r--r--tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr5
-rw-r--r--tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs19
-rw-r--r--tests/ui/type-alias-impl-trait/defining-use-submodule.rs6
-rw-r--r--tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr6
-rw-r--r--tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr16
-rw-r--r--tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs12
-rw-r--r--tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr50
-rw-r--r--tests/ui/type-alias-impl-trait/generic_nondefining_use.rs9
-rw-r--r--tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr44
-rw-r--r--tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs12
-rw-r--r--tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/generic_underconstrained.stderr4
-rw-r--r--tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr8
-rw-r--r--tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs28
-rw-r--r--tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/hidden_behind_struct_field.rs30
-rw-r--r--tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs26
-rw-r--r--tests/ui/type-alias-impl-trait/higher_kinded_params.rs28
-rw-r--r--tests/ui/type-alias-impl-trait/higher_kinded_params2.rs35
-rw-r--r--tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr15
-rw-r--r--tests/ui/type-alias-impl-trait/higher_kinded_params3.rs36
-rw-r--r--tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr28
-rw-r--r--tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs28
-rw-r--r--tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs14
-rw-r--r--tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr11
-rw-r--r--tests/ui/type-alias-impl-trait/inference-cycle.rs8
-rw-r--r--tests/ui/type-alias-impl-trait/inference-cycle.stderr52
-rw-r--r--tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr4
-rw-r--r--tests/ui/type-alias-impl-trait/issue-109054.rs22
-rw-r--r--tests/ui/type-alias-impl-trait/issue-109054.stderr12
-rw-r--r--tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr12
-rw-r--r--tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs21
-rw-r--r--tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr8
-rw-r--r--tests/ui/type-alias-impl-trait/issue-57961.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/issue-60564.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/issue-60564.stderr16
-rw-r--r--tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs5
-rw-r--r--tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr14
-rw-r--r--tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr14
-rw-r--r--tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs7
-rw-r--r--tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr16
-rw-r--r--tests/ui/type-alias-impl-trait/issue-70121.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/issue-70121.stderr15
-rw-r--r--tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/issue-77179.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/multi-error.rs23
-rw-r--r--tests/ui/type-alias-impl-trait/multi-error.stderr15
-rw-r--r--tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr11
-rw-r--r--tests/ui/type-alias-impl-trait/nested-tait-inference2.stderr2
-rw-r--r--tests/ui/type-alias-impl-trait/nested_in_closure.rs17
-rw-r--r--tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr10
-rw-r--r--tests/ui/type-alias-impl-trait/non-defining-method.rs21
-rw-r--r--tests/ui/type-alias-impl-trait/non-defining-method.stderr15
-rw-r--r--tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr55
-rw-r--r--tests/ui/type-alias-impl-trait/normalize-hidden-types.rs60
-rw-r--r--tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs33
-rw-r--r--tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr22
-rw-r--r--tests/ui/type-alias-impl-trait/obligation_ice.rs17
-rw-r--r--tests/ui/type-alias-impl-trait/privacy.rs8
-rw-r--r--tests/ui/type-alias-impl-trait/privacy.stderr11
-rw-r--r--tests/ui/type-alias-impl-trait/reveal_local.rs10
-rw-r--r--tests/ui/type-alias-impl-trait/reveal_local.stderr96
-rw-r--r--tests/ui/type-alias-impl-trait/self-referential-3.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/self-referential-3.stderr15
-rw-r--r--tests/ui/type-alias-impl-trait/self-referential.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/self-referential.stderr6
-rw-r--r--tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs8
-rw-r--r--tests/ui/type-alias-impl-trait/type_of_a_let.rs8
-rw-r--r--tests/ui/type-alias-impl-trait/type_of_a_let.stderr6
95 files changed, 1314 insertions, 172 deletions
diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs
index a1584581e..d9f7c7809 100644
--- a/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs
+++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs
@@ -4,9 +4,9 @@
#![allow(dead_code)]
mod m {
- type Foo = impl std::fmt::Debug;
+ pub(crate) type Foo = impl std::fmt::Debug;
- pub fn foo() -> Foo {
+ pub(crate) fn foo() -> Foo {
22_u32
}
}
diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs
index 5fb7a9473..fd3f9c614 100644
--- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs
+++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs
@@ -4,8 +4,9 @@
// FIXME This should compile, but it currently doesn't
mod m {
- type Foo = impl std::fmt::Debug;
+ pub type Foo = impl std::fmt::Debug;
//~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391]
+ //~| ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391]
pub fn foo() -> Foo {
22_u32
@@ -13,6 +14,7 @@ mod m {
pub fn bar() {
is_send(foo());
+ //~^ ERROR: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0}
}
fn is_send<T: Send>(_: T) {}
diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr
index 1e9a45aac..dd56c59bf 100644
--- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr
+++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr
@@ -1,11 +1,11 @@
error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}`
- --> $DIR/auto-trait-leakage3.rs:7:16
+ --> $DIR/auto-trait-leakage3.rs:7:20
|
-LL | type Foo = impl std::fmt::Debug;
- | ^^^^^^^^^^^^^^^^^^^^
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `m::bar`...
- --> $DIR/auto-trait-leakage3.rs:15:9
+ --> $DIR/auto-trait-leakage3.rs:16:9
|
LL | is_send(foo());
| ^^^^^^^
@@ -17,6 +17,48 @@ note: cycle used when checking item types in module `m`
LL | mod m {
| ^^^^^
-error: aborting due to previous error
+error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}`
+ --> $DIR/auto-trait-leakage3.rs:7:20
+ |
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: ...which requires type-checking `m::bar`...
+ --> $DIR/auto-trait-leakage3.rs:15:5
+ |
+LL | pub fn bar() {
+ | ^^^^^^^^^^^^
+ = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
+note: cycle used when checking item types in module `m`
+ --> $DIR/auto-trait-leakage3.rs:6:1
+ |
+LL | mod m {
+ | ^^^^^
+
+error: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0}` satisfies auto traits
+ --> $DIR/auto-trait-leakage3.rs:16:17
+ |
+LL | is_send(foo());
+ | ------- ^^^^^
+ | |
+ | required by a bound introduced by this call
+ |
+note: opaque type is declared here
+ --> $DIR/auto-trait-leakage3.rs:7:20
+ |
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
+note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
+ --> $DIR/auto-trait-leakage3.rs:15:12
+ |
+LL | pub fn bar() {
+ | ^^^
+note: required by a bound in `is_send`
+ --> $DIR/auto-trait-leakage3.rs:20:19
+ |
+LL | fn is_send<T: Send>(_: T) {}
+ | ^^^^ required by this bound in `is_send`
+
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/type-alias-impl-trait/bound_reduction2.rs b/tests/ui/type-alias-impl-trait/bound_reduction2.rs
index 0bcc9e002..4e9f65d88 100644
--- a/tests/ui/type-alias-impl-trait/bound_reduction2.rs
+++ b/tests/ui/type-alias-impl-trait/bound_reduction2.rs
@@ -13,6 +13,7 @@ trait Trait<U> {}
impl<W> Trait<W> for () {}
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
+ //~^ ERROR non-defining opaque type use
()
//~^ ERROR expected generic type parameter, found `<T as TraitWithAssoc>::Assoc`
}
diff --git a/tests/ui/type-alias-impl-trait/bound_reduction2.stderr b/tests/ui/type-alias-impl-trait/bound_reduction2.stderr
index 3c259bd9e..14f9dbbdb 100644
--- a/tests/ui/type-alias-impl-trait/bound_reduction2.stderr
+++ b/tests/ui/type-alias-impl-trait/bound_reduction2.stderr
@@ -1,5 +1,17 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/bound_reduction2.rs:15:46
+ |
+LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
+ | ^^^^^^^^^^^^^ argument `<T as TraitWithAssoc>::Assoc` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/bound_reduction2.rs:9:15
+ |
+LL | type Foo<V> = impl Trait<V>;
+ | ^^^^^^^^^^^^^
+
error[E0792]: expected generic type parameter, found `<T as TraitWithAssoc>::Assoc`
- --> $DIR/bound_reduction2.rs:16:5
+ --> $DIR/bound_reduction2.rs:17:5
|
LL | type Foo<V> = impl Trait<V>;
| - this generic parameter must be used with a generic type parameter
@@ -7,6 +19,6 @@ LL | type Foo<V> = impl Trait<V>;
LL | ()
| ^^
-error: aborting due to previous error
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs
new file mode 100644
index 000000000..5a9e87c09
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs
@@ -0,0 +1,16 @@
+#![feature(type_alias_impl_trait)]
+
+use std::fmt::{Debug, Display};
+
+struct Struct<V: Display>(Option<V>);
+
+// Make sure that, in contrast to type aliases without opaque types,
+// we actually do a wf check for the aliased type.
+type Foo<T: Debug> = (impl Debug, Struct<T>);
+//~^ ERROR: `T` doesn't implement `std::fmt::Display`
+
+fn foo<U: Debug + Display>() -> Foo<U> {
+ (Vec::<U>::new(), Struct(None))
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked3.stderr b/tests/ui/type-alias-impl-trait/bounds-are-checked3.stderr
new file mode 100644
index 000000000..a845cba77
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/bounds-are-checked3.stderr
@@ -0,0 +1,20 @@
+error[E0277]: `T` doesn't implement `std::fmt::Display`
+ --> $DIR/bounds-are-checked3.rs:9:35
+ |
+LL | type Foo<T: Debug> = (impl Debug, Struct<T>);
+ | ^^^^^^^^^ `T` cannot be formatted with the default formatter
+ |
+ = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+note: required by a bound in `Struct`
+ --> $DIR/bounds-are-checked3.rs:5:18
+ |
+LL | struct Struct<V: Display>(Option<V>);
+ | ^^^^^^^ required by this bound in `Struct`
+help: consider further restricting this bound
+ |
+LL | type Foo<T: Debug + std::fmt::Display> = (impl Debug, Struct<T>);
+ | +++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/bounds.rs b/tests/ui/type-alias-impl-trait/bounds.rs
new file mode 100644
index 000000000..dc05b70c5
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/bounds.rs
@@ -0,0 +1,16 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+use std::fmt::Debug;
+
+// No need to report the `type_alias_bounds` lint, as
+// the moment an opaque type is mentioned, we actually do check
+// type alias bounds.
+type Foo<T: Debug> = (impl Debug, usize);
+
+fn foo<U: Debug>() -> Foo<U> {
+ (Vec::<U>::new(), 1234)
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/closure_args.rs b/tests/ui/type-alias-impl-trait/closure_args.rs
index c5e7af81d..243f9cd6d 100644
--- a/tests/ui/type-alias-impl-trait/closure_args.rs
+++ b/tests/ui/type-alias-impl-trait/closure_args.rs
@@ -11,6 +11,13 @@ fn run<F: FnOnce(Input) -> ()>(f: F, i: Input) {
f(i);
}
-fn main() {
- run(|x: u32| {println!("{x}");}, 0);
+fn bop(_: Input) {
+ run(
+ |x: u32| {
+ println!("{x}");
+ },
+ 0,
+ );
}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/closure_args2.rs b/tests/ui/type-alias-impl-trait/closure_args2.rs
index 82386c280..1dd5c3e40 100644
--- a/tests/ui/type-alias-impl-trait/closure_args2.rs
+++ b/tests/ui/type-alias-impl-trait/closure_args2.rs
@@ -1,10 +1,12 @@
-// run-pass
+// check-pass
#![feature(type_alias_impl_trait)]
trait Foo {
// This was reachable in https://github.com/rust-lang/rust/issues/100800
- fn foo(&self) { unreachable!() }
+ fn foo(&self) {
+ unreachable!()
+ }
}
impl<T> Foo for T {}
@@ -14,10 +16,17 @@ impl B {
}
type Input = impl Foo;
-fn run1<F: FnOnce(Input)>(f: F, i: Input) {f(i)}
-fn run2<F: FnOnce(B)>(f: F, i: B) {f(i)}
+fn run1<F: FnOnce(Input)>(f: F, i: Input) {
+ f(i)
+}
+fn run2<F: FnOnce(B)>(f: F, i: B) {
+ f(i)
+}
-fn main() {
- run1(|x: B| {x.foo()}, B);
- run2(|x: B| {x.foo()}, B);
+fn bop() -> Input {
+ run1(|x: B| x.foo(), B);
+ run2(|x: B| x.foo(), B);
+ panic!()
}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/coherence.stderr b/tests/ui/type-alias-impl-trait/coherence.stderr
index 00b0dbbb5..c923eb08a 100644
--- a/tests/ui/type-alias-impl-trait/coherence.stderr
+++ b/tests/ui/type-alias-impl-trait/coherence.stderr
@@ -4,7 +4,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
LL | impl<T> foreign_crate::ForeignTrait for AliasOfForeignType<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------
| | |
- | | type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate
+ | | `AliasOfForeignType<T>` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
diff --git a/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs
new file mode 100644
index 000000000..39b3d535a
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs
@@ -0,0 +1,25 @@
+// When checking whether these two impls overlap, we could detect that we
+// would require the hidden type of `TAIT` to be equal to both `u32` and `i32`
+// and therefore accept them as disjoint. That is annoying to implement with
+// the current system because we would have to add the following to each
+// returning branch in coherence.
+//
+// let _ = infcx.take_opaque_types();
+//
+// @lcnr: Because of this I decided to not bother and cause this to fail instead.
+// In the future we can definitely modify the compiler to accept this
+// again.
+#![feature(type_alias_impl_trait)]
+
+trait Trait {}
+
+type TAIT = impl Sized;
+
+impl Trait for (TAIT, TAIT) {}
+
+impl Trait for (u32, i32) {}
+//~^ ERROR conflicting implementations of trait `Trait` for type `(TAIT, TAIT)`
+
+fn define() -> TAIT {}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.stderr b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.stderr
new file mode 100644
index 000000000..f2aee7986
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `Trait` for type `(TAIT, TAIT)`
+ --> $DIR/coherence_different_hidden_ty.rs:20:1
+ |
+LL | impl Trait for (TAIT, TAIT) {}
+ | --------------------------- first implementation here
+LL |
+LL | impl Trait for (u32, i32) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(TAIT, TAIT)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/tests/ui/type-alias-impl-trait/coherence_generalization.rs b/tests/ui/type-alias-impl-trait/coherence_generalization.rs
index 5c9ad9498..679b2b0f1 100644
--- a/tests/ui/type-alias-impl-trait/coherence_generalization.rs
+++ b/tests/ui/type-alias-impl-trait/coherence_generalization.rs
@@ -1,5 +1,7 @@
// check-pass
+// FIXME(type_alias_impl_trait): What does this test? This needs a comment
+// explaining what we're worried about here.
#![feature(type_alias_impl_trait)]
trait Trait {}
type Opaque<T> = impl Sized;
diff --git a/tests/ui/type-alias-impl-trait/cross_inference.rs b/tests/ui/type-alias-impl-trait/cross_inference.rs
index dafaf40a6..5eaf0ddda 100644
--- a/tests/ui/type-alias-impl-trait/cross_inference.rs
+++ b/tests/ui/type-alias-impl-trait/cross_inference.rs
@@ -1,10 +1,12 @@
+// revisions: current next
+//[next] compile-flags: -Ztrait-solver=next
// check-pass
#![feature(type_alias_impl_trait)]
fn main() {
- type T = impl Copy;
- let foo: T = (1u32, 2u32);
+ type Tait = impl Copy;
+ let foo: Tait = (1u32, 2u32);
let x: (_, _) = foo;
println!("{:?}", x);
}
diff --git a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
new file mode 100644
index 000000000..44158349f
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs
@@ -0,0 +1,12 @@
+// compile-flags: --crate-type=lib -Cdebuginfo=2
+// build-pass
+
+#![feature(type_alias_impl_trait)]
+
+type Debuggable = impl core::fmt::Debug;
+
+static mut TEST: Option<Debuggable> = None;
+
+fn foo() -> Debuggable {
+ 0u32
+}
diff --git a/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr b/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr
index fbfa0ccf1..d60f1ffbc 100644
--- a/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr
+++ b/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr
@@ -19,6 +19,11 @@ LL | ""
|
= note: expected opaque type `Boo`
found reference `&'static str`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/declared_but_not_defined_in_scope.rs:10:4
+ |
+LL | fn bomp() -> boo::Boo {
+ | ^^^^
error: aborting due to 2 previous errors
diff --git a/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs b/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs
new file mode 100644
index 000000000..5a421ea1d
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs
@@ -0,0 +1,19 @@
+// User type annotation in fn bodies is a a valid defining site for opaque types.
+// check-pass
+#![feature(type_alias_impl_trait)]
+
+trait Equate { type Proj; }
+impl<T> Equate for T { type Proj = T; }
+
+trait Indirect { type Ty; }
+impl<A, B: Equate<Proj = A>> Indirect for (A, B) { type Ty = (); }
+
+type Opq = impl Sized;
+fn define_1(_: Opq) {
+ let _ = None::<<(Opq, u8) as Indirect>::Ty>;
+}
+fn define_2() -> Opq {
+ 0u8
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/defining-use-submodule.rs b/tests/ui/type-alias-impl-trait/defining-use-submodule.rs
index 8b51f5571..4d84b2cbb 100644
--- a/tests/ui/type-alias-impl-trait/defining-use-submodule.rs
+++ b/tests/ui/type-alias-impl-trait/defining-use-submodule.rs
@@ -11,12 +11,12 @@ type Foo = impl std::fmt::Display;
type Bar = impl std::fmt::Display;
mod foo {
- pub fn foo() -> super::Foo {
+ pub(crate) fn foo() -> super::Foo {
"foo"
}
- pub mod bar {
- pub fn bar() -> crate::Bar {
+ pub(crate) mod bar {
+ pub(crate) fn bar() -> crate::Bar {
1
}
}
diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs
index e5bfbfdae..b2842df15 100644
--- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs
+++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs
@@ -2,7 +2,7 @@
type Tait<'a> = impl Sized + 'a;
-fn foo<'a, 'b>() {
+fn foo<'a, 'b>() -> Tait<'a> {
if false {
if { return } {
let y: Tait<'b> = 1i32;
@@ -10,6 +10,7 @@ fn foo<'a, 'b>() {
}
}
let x: Tait<'a> = ();
+ x
}
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr
index f2eb7bc4d..b138f9d5c 100644
--- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr
+++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr
@@ -5,10 +5,10 @@ LL | let y: Tait<'b> = 1i32;
| ^^^^ expected `()`, got `i32`
|
note: previous use here
- --> $DIR/different_defining_uses_never_type-2.rs:12:23
+ --> $DIR/different_defining_uses_never_type-2.rs:7:14
|
-LL | let x: Tait<'a> = ();
- | ^^
+LL | if { return } {
+ | ^^^^^^
error: aborting due to previous error
diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs
index 2b30a9cd5..a4ac27378 100644
--- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs
+++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs
@@ -2,7 +2,7 @@
type Tait<T> = impl Sized;
-fn foo<T, U>() {
+fn foo<T, U>() -> Tait<T> {
if false {
if { return } {
let y: Tait<U> = 1i32;
@@ -10,6 +10,7 @@ fn foo<T, U>() {
}
}
let x: Tait<T> = ();
+ x
}
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
index 9d938a616..14ced3418 100644
--- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
+++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
@@ -9,6 +9,7 @@ impl<'a, T: ?Sized> Captures<'a> for T {}
type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
+ //~^ ERROR non-defining opaque type use
t
//~^ ERROR non-defining opaque type use
}
diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
index 72e1ef4b4..4da69a705 100644
--- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
@@ -1,5 +1,17 @@
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_lifetime_param.rs:12:5
+ --> $DIR/generic_duplicate_lifetime_param.rs:11:26
+ |
+LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
+ | ^^^^^^^^^^^ generic argument `'a` used twice
+ |
+note: for this opaque type
+ --> $DIR/generic_duplicate_lifetime_param.rs:9:20
+ |
+LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/generic_duplicate_lifetime_param.rs:13:5
|
LL | t
| ^
@@ -10,5 +22,5 @@ note: lifetime used multiple times
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
-error: aborting due to previous error
+error: aborting due to 2 previous errors
diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
index 80462f8ac..1e391b55a 100644
--- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
+++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
@@ -1,5 +1,12 @@
#![feature(type_alias_impl_trait)]
+//! This test checks various cases where we are using the same
+//! generic parameter twice in the parameter list of a TAIT.
+//! Within defining scopes that is not legal, because the hidden type
+//! is not fully defined then. This could cause us to have a TAIT
+//! that doesn't have a hidden type for all possible combinations of generic
+//! parameters passed to it.
+
use std::fmt::Debug;
fn main() {}
@@ -7,7 +14,6 @@ fn main() {}
// test that unused generic parameters are ok
type TwoTys<T, U> = impl Debug;
-
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
@@ -16,18 +22,20 @@ type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
-
fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
+ //~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}
fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
+ //~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}
fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
+ //~^ ERROR non-defining opaque type use in defining scope
t
//~^ ERROR non-defining opaque type use in defining scope
}
diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
index 98e4bfea1..d8330771d 100644
--- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
@@ -1,38 +1,74 @@
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:21:5
+ --> $DIR/generic_duplicate_param_use.rs:25:30
+ |
+LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
+ | ^^^^^^^^^^^^ generic argument `T` used twice
+ |
+note: for this opaque type
+ --> $DIR/generic_duplicate_param_use.rs:15:21
+ |
+LL | type TwoTys<T, U> = impl Debug;
+ | ^^^^^^^^^^
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/generic_duplicate_param_use.rs:27:5
|
LL | t
| ^
|
note: type used multiple times
- --> $DIR/generic_duplicate_param_use.rs:8:13
+ --> $DIR/generic_duplicate_param_use.rs:15:13
|
LL | type TwoTys<T, U> = impl Debug;
| ^ ^
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:26:5
+ --> $DIR/generic_duplicate_param_use.rs:31:36
+ |
+LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
+ | ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice
+ |
+note: for this opaque type
+ --> $DIR/generic_duplicate_param_use.rs:21:29
+ |
+LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/generic_duplicate_param_use.rs:33:5
|
LL | t
| ^
|
note: lifetime used multiple times
- --> $DIR/generic_duplicate_param_use.rs:15:19
+ --> $DIR/generic_duplicate_param_use.rs:21:19
|
LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:31:5
+ --> $DIR/generic_duplicate_param_use.rs:37:50
+ |
+LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
+ | ^^^^^^^^^^^^^^^ generic argument `N` used twice
+ |
+note: for this opaque type
+ --> $DIR/generic_duplicate_param_use.rs:23:50
+ |
+LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
+ | ^^^^^^^^^^
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/generic_duplicate_param_use.rs:39:5
|
LL | t
| ^
|
note: constant used multiple times
- --> $DIR/generic_duplicate_param_use.rs:17:16
+ --> $DIR/generic_duplicate_param_use.rs:23:16
|
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: aborting due to 6 previous errors
diff --git a/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs b/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs
index e7b8567b9..68f4c6923 100644
--- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs
+++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs
@@ -13,16 +13,19 @@ type OneConst<const X: usize> = impl Debug;
// Not defining uses, because they doesn't define *all* possible generics.
fn concrete_ty() -> OneTy<u32> {
+ //~^ ERROR: non-defining opaque type use in defining scope
5u32
- //~^ ERROR expected generic type parameter, found `u32`
+ //~^ ERROR: expected generic type parameter, found `u32`
}
fn concrete_lifetime() -> OneLifetime<'static> {
+ //~^ ERROR: non-defining opaque type use in defining scope
6u32
- //~^ ERROR expected generic lifetime parameter, found `'static`
+ //~^ ERROR: expected generic lifetime parameter, found `'static`
}
fn concrete_const() -> OneConst<{ 123 }> {
+ //~^ ERROR: non-defining opaque type use in defining scope
7u32
- //~^ ERROR expected generic constant parameter, found `123`
+ //~^ ERROR: expected generic constant parameter, found `123`
}
diff --git a/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr
index 966fe823f..e3b7b1a76 100644
--- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr
@@ -1,5 +1,17 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/generic_nondefining_use.rs:15:21
+ |
+LL | fn concrete_ty() -> OneTy<u32> {
+ | ^^^^^^^^^^ argument `u32` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/generic_nondefining_use.rs:7:17
+ |
+LL | type OneTy<T> = impl Debug;
+ | ^^^^^^^^^^
+
error[E0792]: expected generic type parameter, found `u32`
- --> $DIR/generic_nondefining_use.rs:16:5
+ --> $DIR/generic_nondefining_use.rs:17:5
|
LL | type OneTy<T> = impl Debug;
| - this generic parameter must be used with a generic type parameter
@@ -7,8 +19,20 @@ LL | type OneTy<T> = impl Debug;
LL | 5u32
| ^^^^
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/generic_nondefining_use.rs:21:27
+ |
+LL | fn concrete_lifetime() -> OneLifetime<'static> {
+ | ^^^^^^^^^^^^^^^^^^^^ argument `'static` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/generic_nondefining_use.rs:9:24
+ |
+LL | type OneLifetime<'a> = impl Debug;
+ | ^^^^^^^^^^
+
error[E0792]: expected generic lifetime parameter, found `'static`
- --> $DIR/generic_nondefining_use.rs:21:5
+ --> $DIR/generic_nondefining_use.rs:23:5
|
LL | type OneLifetime<'a> = impl Debug;
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
@@ -16,8 +40,20 @@ LL | type OneLifetime<'a> = impl Debug;
LL | 6u32
| ^^^^
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/generic_nondefining_use.rs:27:24
+ |
+LL | fn concrete_const() -> OneConst<{ 123 }> {
+ | ^^^^^^^^^^^^^^^^^ argument `123` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/generic_nondefining_use.rs:11:33
+ |
+LL | type OneConst<const X: usize> = impl Debug;
+ | ^^^^^^^^^^
+
error[E0792]: expected generic constant parameter, found `123`
- --> $DIR/generic_nondefining_use.rs:26:5
+ --> $DIR/generic_nondefining_use.rs:29:5
|
LL | type OneConst<const X: usize> = impl Debug;
| -------------- this generic parameter must be used with a generic constant parameter
@@ -25,6 +61,6 @@ LL | type OneConst<const X: usize> = impl Debug;
LL | 7u32
| ^^^^
-error: aborting due to 3 previous errors
+error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs
index cdd8f6f19..c60f5c11c 100644
--- a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs
+++ b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs
@@ -5,12 +5,12 @@ fn main() {
let x = wrong_generic(&y);
let z: i32 = x;
//~^ ERROR expected generic type parameter, found `&i32`
-}
-type WrongGeneric<T> = impl 'static;
-//~^ ERROR: at least one trait must be specified
+ type WrongGeneric<T> = impl 'static;
+ //~^ ERROR: at least one trait must be specified
-fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
- t
- //~^ ERROR the parameter type `T` may not live long enough
+ fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
+ t
+ //~^ ERROR the parameter type `T` may not live long enough
+ }
}
diff --git a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr
index fa79e51e9..8c3a25dbf 100644
--- a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr
@@ -1,8 +1,8 @@
error: at least one trait must be specified
- --> $DIR/generic_type_does_not_live_long_enough.rs:10:24
+ --> $DIR/generic_type_does_not_live_long_enough.rs:9:28
|
-LL | type WrongGeneric<T> = impl 'static;
- | ^^^^^^^^^^^^
+LL | type WrongGeneric<T> = impl 'static;
+ | ^^^^^^^^^^^^
error[E0792]: expected generic type parameter, found `&i32`
--> $DIR/generic_type_does_not_live_long_enough.rs:6:18
@@ -10,19 +10,19 @@ error[E0792]: expected generic type parameter, found `&i32`
LL | let z: i32 = x;
| ^
...
-LL | type WrongGeneric<T> = impl 'static;
- | - this generic parameter must be used with a generic type parameter
+LL | type WrongGeneric<T> = impl 'static;
+ | - this generic parameter must be used with a generic type parameter
error[E0310]: the parameter type `T` may not live long enough
- --> $DIR/generic_type_does_not_live_long_enough.rs:14:5
+ --> $DIR/generic_type_does_not_live_long_enough.rs:13:9
|
-LL | t
- | ^ ...so that the type `T` will meet its required lifetime bounds
+LL | t
+ | ^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
-LL | fn wrong_generic<T: 'static>(t: T) -> WrongGeneric<T> {
- | +++++++++
+LL | fn wrong_generic<T: 'static>(t: T) -> WrongGeneric<T> {
+ | +++++++++
error: aborting due to 3 previous errors
diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr b/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr
index c73288329..bc9280127 100644
--- a/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr
@@ -4,11 +4,11 @@ error[E0277]: the trait bound `T: Trait` is not satisfied
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
|
-note: required by a bound in `Underconstrained`
+note: required by a bound on the type alias `Underconstrained`
--> $DIR/generic_underconstrained.rs:6:26
|
LL | type Underconstrained<T: Trait> = impl Send;
- | ^^^^^ required by this bound in `Underconstrained`
+ | ^^^^^ required by this bound
help: consider restricting type parameter `T`
|
LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {
diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr b/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr
index d77d978aa..fdc9ec090 100644
--- a/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr
+++ b/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr
@@ -4,11 +4,11 @@ error[E0277]: `U` doesn't implement `Debug`
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
| ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
-note: required by a bound in `Underconstrained`
+note: required by a bound on the type alias `Underconstrained`
--> $DIR/generic_underconstrained2.rs:5:26
|
LL | type Underconstrained<T: std::fmt::Debug> = impl Send;
- | ^^^^^^^^^^^^^^^ required by this bound in `Underconstrained`
+ | ^^^^^^^^^^^^^^^ required by this bound
help: consider restricting type parameter `U`
|
LL | fn underconstrained<U: std::fmt::Debug>(_: U) -> Underconstrained<U> {
@@ -20,11 +20,11 @@ error[E0277]: `V` doesn't implement `Debug`
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
| ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
-note: required by a bound in `Underconstrained2`
+note: required by a bound on the type alias `Underconstrained2`
--> $DIR/generic_underconstrained2.rs:13:27
|
LL | type Underconstrained2<T: std::fmt::Debug> = impl Send;
- | ^^^^^^^^^^^^^^^ required by this bound in `Underconstrained2`
+ | ^^^^^^^^^^^^^^^ required by this bound
help: consider restricting type parameter `V`
|
LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained2<V> {
diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs
new file mode 100644
index 000000000..eb19b49c7
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs
@@ -0,0 +1,28 @@
+//! This test shows that a field type that is a projection that resolves to an opaque,
+//! is not a defining use. While we could substitute the struct generics, that would
+//! mean we would have to walk all substitutions of an `Foo`, which can quickly
+//! degenerate into looking at an exponential number of types depending on the complexity
+//! of a program.
+
+#![feature(impl_trait_in_assoc_type)]
+
+struct Bar;
+
+trait Trait: Sized {
+ type Assoc;
+ fn foo() -> Foo<Self>;
+}
+
+impl Trait for Bar {
+ type Assoc = impl std::fmt::Debug;
+ fn foo() -> Foo<Bar> {
+ Foo { field: () }
+ //~^ ERROR: mismatched types
+ }
+}
+
+struct Foo<T: Trait> {
+ field: <T as Trait>::Assoc,
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr
new file mode 100644
index 000000000..648efd1cb
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr
@@ -0,0 +1,20 @@
+error[E0308]: mismatched types
+ --> $DIR/hidden_behind_projection_behind_struct_field.rs:19:22
+ |
+LL | type Assoc = impl std::fmt::Debug;
+ | -------------------- the expected opaque type
+LL | fn foo() -> Foo<Bar> {
+LL | Foo { field: () }
+ | ^^ expected opaque type, found `()`
+ |
+ = note: expected opaque type `<Bar as Trait>::Assoc`
+ found unit type `()`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/hidden_behind_projection_behind_struct_field.rs:18:8
+ |
+LL | fn foo() -> Foo<Bar> {
+ | ^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field.rs
new file mode 100644
index 000000000..58778702d
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field.rs
@@ -0,0 +1,30 @@
+//! This test shows that the appearance of an opaque type
+//! in the substs of a struct are enough to make it count
+//! for making the function a defining use. It doesn't matter
+//! if the opaque type is actually used in the field.
+
+#![feature(impl_trait_in_assoc_type)]
+// check-pass
+
+use std::marker::PhantomData;
+
+struct Bar;
+
+trait Trait: Sized {
+ type Assoc;
+ fn foo() -> Foo<Self::Assoc>;
+}
+
+impl Trait for Bar {
+ type Assoc = impl std::fmt::Debug;
+ fn foo() -> Foo<Self::Assoc> {
+ let foo: Foo<()> = Foo { field: PhantomData };
+ foo
+ }
+}
+
+struct Foo<T> {
+ field: PhantomData<T>,
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs
new file mode 100644
index 000000000..e440dce5e
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs
@@ -0,0 +1,26 @@
+//! This test shows that we can even follow projections
+//! into associated types of the same impl if they are
+//! indirectly mentioned in a struct field.
+
+#![feature(impl_trait_in_assoc_type)]
+// check-pass
+
+struct Bar;
+
+trait Trait: Sized {
+ type Assoc;
+ fn foo() -> Foo;
+}
+
+impl Trait for Bar {
+ type Assoc = impl std::fmt::Debug;
+ fn foo() -> Foo {
+ Foo { field: () }
+ }
+}
+
+struct Foo {
+ field: <Bar as Trait>::Assoc,
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params.rs
new file mode 100644
index 000000000..db1a3a1c7
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/higher_kinded_params.rs
@@ -0,0 +1,28 @@
+//! This test checks that walking into binders
+//! during opaque type collection does not ICE or raise errors.
+
+// edition: 2021
+
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+trait B {
+ type C;
+}
+
+struct A;
+
+impl<'a> B for &'a A {
+ type C = ();
+}
+
+struct Terminator;
+
+type Successors<'a> = impl std::fmt::Debug + 'a;
+
+impl Terminator {
+ fn successors(&self, _: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {}
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs
new file mode 100644
index 000000000..f011e5b21
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs
@@ -0,0 +1,35 @@
+//! This test checks the behaviour of walking into binders
+//! and normalizing something behind them actually works.
+
+// edition: 2021
+
+#![feature(type_alias_impl_trait)]
+
+trait B {
+ type C;
+}
+
+struct A;
+
+impl<'a> B for &'a A {
+ type C = Tait;
+}
+
+type Tait = impl std::fmt::Debug;
+
+struct Terminator;
+
+type Successors<'a> = impl std::fmt::Debug + 'a;
+
+impl Terminator {
+ fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
+ f = g;
+ //~^ ERROR item constrains opaque type that is not in its signature
+ }
+}
+
+fn g(_: &()) -> String {
+ String::new()
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr b/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr
new file mode 100644
index 000000000..39f584dd4
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr
@@ -0,0 +1,15 @@
+error: item constrains opaque type that is not in its signature
+ --> $DIR/higher_kinded_params2.rs:26:13
+ |
+LL | f = g;
+ | ^
+ |
+ = note: this item must mention the opaque type in its signature in order to be able to register hidden types
+note: this item must mention the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/higher_kinded_params2.rs:25:8
+ |
+LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
+ | ^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs
new file mode 100644
index 000000000..6edfccaf7
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs
@@ -0,0 +1,36 @@
+//! This test checks that we can't actually have an opaque type behind
+//! a binder that references variables from that binder.
+
+// edition: 2021
+
+#![feature(type_alias_impl_trait)]
+
+trait B {
+ type C;
+}
+
+struct A;
+
+impl<'a> B for &'a A {
+ type C = Tait<'a>;
+}
+
+type Tait<'a> = impl std::fmt::Debug + 'a;
+
+struct Terminator;
+
+type Successors<'a> = impl std::fmt::Debug + 'a;
+
+impl Terminator {
+ fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
+ f = g;
+ //~^ ERROR mismatched types
+ //~| ERROR item constrains opaque type that is not in its signature
+ }
+}
+
+fn g(x: &()) -> &() {
+ x
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr
new file mode 100644
index 000000000..14372d8f3
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr
@@ -0,0 +1,28 @@
+error: item constrains opaque type that is not in its signature
+ --> $DIR/higher_kinded_params3.rs:26:13
+ |
+LL | f = g;
+ | ^
+ |
+ = note: this item must mention the opaque type in its signature in order to be able to register hidden types
+note: this item must mention the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/higher_kinded_params3.rs:25:8
+ |
+LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {
+ | ^^^^^^^^^^
+
+error[E0308]: mismatched types
+ --> $DIR/higher_kinded_params3.rs:26:9
+ |
+LL | type Tait<'a> = impl std::fmt::Debug + 'a;
+ | ------------------------- the expected opaque type
+...
+LL | f = g;
+ | ^^^^^ one type is more general than the other
+ |
+ = note: expected fn pointer `for<'x> fn(&'x ()) -> Tait<'x>`
+ found fn pointer `for<'a> fn(&'a ()) -> &'a ()`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs
new file mode 100644
index 000000000..a3f65146f
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs
@@ -0,0 +1,28 @@
+#![feature(impl_trait_in_assoc_type)]
+
+// We weren't checking that the trait and impl generics line up in the
+// normalization-shortcut code in `OpaqueTypeCollector`.
+
+use std::ops::Deref;
+
+trait Foo {
+ type Bar<'a>;
+
+ type Baz<'a>;
+
+ fn test<'a>() -> Self::Bar<'a>;
+}
+
+impl Foo for () {
+ type Bar<'a> = impl Deref<Target = Self::Baz<'a>>;
+
+ type Baz<T> = impl Sized;
+ //~^ ERROR type `Baz` has 1 type parameter but its trait declaration has 0 type parameters
+ //~| ERROR unconstrained opaque type
+
+ fn test<'a>() -> Self::Bar<'a> {
+ &()
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr
new file mode 100644
index 000000000..13f5d8b8e
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr
@@ -0,0 +1,20 @@
+error[E0049]: type `Baz` has 1 type parameter but its trait declaration has 0 type parameters
+ --> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:14
+ |
+LL | type Baz<'a>;
+ | -- expected 0 type parameters
+...
+LL | type Baz<T> = impl Sized;
+ | ^ found 1 type parameter
+
+error: unconstrained opaque type
+ --> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:19
+ |
+LL | type Baz<T> = impl Sized;
+ | ^^^^^^^^^^
+ |
+ = note: `Baz` must be used in combination with a concrete type within the same impl
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0049`.
diff --git a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs
new file mode 100644
index 000000000..00d1a1a22
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs
@@ -0,0 +1,14 @@
+#![feature(type_alias_impl_trait)]
+#![feature(auto_traits)]
+
+type Alias = (impl Sized, u8);
+
+auto trait Trait {}
+impl Trait for Alias {}
+//~^ ERROR traits with a default impl, like `Trait`, cannot be implemented for type alias `Alias`
+
+fn _def() -> Alias {
+ (42, 42)
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr
new file mode 100644
index 000000000..c312ee7de
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr
@@ -0,0 +1,11 @@
+error[E0321]: traits with a default impl, like `Trait`, cannot be implemented for type alias `Alias`
+ --> $DIR/impl_for_weak_alias.rs:7:1
+ |
+LL | impl Trait for Alias {}
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: a trait object implements `Trait` if and only if `Trait` is one of the trait object's trait bounds
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0321`.
diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.rs b/tests/ui/type-alias-impl-trait/inference-cycle.rs
index 79caddf79..20175a4fe 100644
--- a/tests/ui/type-alias-impl-trait/inference-cycle.rs
+++ b/tests/ui/type-alias-impl-trait/inference-cycle.rs
@@ -2,8 +2,9 @@
#![allow(dead_code)]
mod m {
- type Foo = impl std::fmt::Debug;
+ pub type Foo = impl std::fmt::Debug;
//~^ ERROR cycle detected
+ //~| ERROR cycle detected
// Cycle: error today, but it'd be nice if it eventually worked
@@ -13,10 +14,11 @@ mod m {
pub fn bar() {
is_send(foo()); // Today: error
+ //~^ ERROR: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits
}
- fn baz() {
- let f: Foo = 22_u32;
+ fn baz() -> Foo {
+ ()
}
fn is_send<T: Send>(_: T) {}
diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.stderr b/tests/ui/type-alias-impl-trait/inference-cycle.stderr
index b9d646b92..4d5f36747 100644
--- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr
+++ b/tests/ui/type-alias-impl-trait/inference-cycle.stderr
@@ -1,11 +1,11 @@
error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}`
- --> $DIR/inference-cycle.rs:5:16
+ --> $DIR/inference-cycle.rs:5:20
|
-LL | type Foo = impl std::fmt::Debug;
- | ^^^^^^^^^^^^^^^^^^^^
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `m::bar`...
- --> $DIR/inference-cycle.rs:15:9
+ --> $DIR/inference-cycle.rs:16:9
|
LL | is_send(foo()); // Today: error
| ^^^^^^^
@@ -17,6 +17,48 @@ note: cycle used when checking item types in module `m`
LL | mod m {
| ^^^^^
-error: aborting due to previous error
+error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}`
+ --> $DIR/inference-cycle.rs:5:20
+ |
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: ...which requires type-checking `m::bar`...
+ --> $DIR/inference-cycle.rs:15:5
+ |
+LL | pub fn bar() {
+ | ^^^^^^^^^^^^
+ = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
+note: cycle used when checking item types in module `m`
+ --> $DIR/inference-cycle.rs:4:1
+ |
+LL | mod m {
+ | ^^^^^
+
+error: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits
+ --> $DIR/inference-cycle.rs:16:17
+ |
+LL | is_send(foo()); // Today: error
+ | ------- ^^^^^
+ | |
+ | required by a bound introduced by this call
+ |
+note: opaque type is declared here
+ --> $DIR/inference-cycle.rs:5:20
+ |
+LL | pub type Foo = impl std::fmt::Debug;
+ | ^^^^^^^^^^^^^^^^^^^^
+note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
+ --> $DIR/inference-cycle.rs:15:12
+ |
+LL | pub fn bar() {
+ | ^^^
+note: required by a bound in `is_send`
+ --> $DIR/inference-cycle.rs:24:19
+ |
+LL | fn is_send<T: Send>(_: T) {}
+ | ^^^^ required by this bound in `is_send`
+
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr
index 2beed73cb..6ec5d13f8 100644
--- a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr
+++ b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr
@@ -12,10 +12,10 @@ LL | let x: Self::Foo = ();
= note: expected opaque type `<() as Foo>::Foo`
found unit type `()`
note: this item must have the opaque type in its signature in order to be able to register hidden types
- --> $DIR/invalid_impl_trait_in_assoc_ty.rs:10:5
+ --> $DIR/invalid_impl_trait_in_assoc_ty.rs:10:8
|
LL | fn bar() {
- | ^^^^^^^^
+ | ^^^
error: aborting due to previous error
diff --git a/tests/ui/type-alias-impl-trait/issue-109054.rs b/tests/ui/type-alias-impl-trait/issue-109054.rs
new file mode 100644
index 000000000..1fbec47b1
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/issue-109054.rs
@@ -0,0 +1,22 @@
+// edition:2021
+
+#![feature(type_alias_impl_trait)]
+
+struct CallMe;
+
+type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
+type FnType = impl Fn(&u32) -> ReturnType;
+
+impl std::ops::Deref for CallMe {
+ type Target = FnType;
+
+ fn deref(&self) -> &Self::Target {
+ fn inner(val: &u32) -> ReturnType {
+ async move { *val * 2 }
+ }
+
+ &inner //~ ERROR: expected generic lifetime parameter, found `'_`
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-109054.stderr b/tests/ui/type-alias-impl-trait/issue-109054.stderr
new file mode 100644
index 000000000..a611b9fe4
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/issue-109054.stderr
@@ -0,0 +1,12 @@
+error[E0792]: expected generic lifetime parameter, found `'_`
+ --> $DIR/issue-109054.rs:18:9
+ |
+LL | type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
+ | -- this generic parameter must be used with a generic lifetime parameter
+...
+LL | &inner
+ | ^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs
index 4a11bb502..b89c3e459 100644
--- a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs
+++ b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs
@@ -1,9 +1,10 @@
#![feature(type_alias_impl_trait)]
+// check-pass
+
type Foo = impl Fn() -> Foo;
fn foo() -> Foo {
-//~^ ERROR: overflow evaluating the requirement
foo
}
diff --git a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
deleted file mode 100644
index 0a34e8486..000000000
--- a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0275]: overflow evaluating the requirement `Foo: Sized`
- --> $DIR/issue-53398-cyclic-types.rs:5:13
- |
-LL | fn foo() -> Foo {
- | ^^^
- |
- = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)
- = note: required because it appears within the type `fn() -> Foo {foo}`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0275`.
diff --git a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs
index a3f126d56..a213dbba4 100644
--- a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs
+++ b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs
@@ -1,19 +1,22 @@
#![feature(generators, generator_trait, rustc_attrs)]
#![feature(type_alias_impl_trait)]
-use std::ops::Generator;
+// check-pass
-type GenOnce<Y, R> = impl Generator<Yield = Y, Return = R>;
+mod gen {
+ use std::ops::Generator;
-const fn const_generator<Y, R>(yielding: Y, returning: R) -> GenOnce<Y, R> {
- move || {
- yield yielding;
+ pub type GenOnce<Y, R> = impl Generator<Yield = Y, Return = R>;
- return returning;
+ pub const fn const_generator<Y, R>(yielding: Y, returning: R) -> GenOnce<Y, R> {
+ move || {
+ yield yielding;
+
+ return returning;
+ }
}
}
-const FOO: GenOnce<usize, usize> = const_generator(10, 100);
+const FOO: gen::GenOnce<usize, usize> = gen::const_generator(10, 100);
-#[rustc_error]
-fn main() {} //~ ERROR
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr
deleted file mode 100644
index eb1c9603a..000000000
--- a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: fatal error triggered by #[rustc_error]
- --> $DIR/issue-53678-generator-and-const-fn.rs:19:1
- |
-LL | fn main() {}
- | ^^^^^^^^^
-
-error: aborting due to previous error
-
diff --git a/tests/ui/type-alias-impl-trait/issue-57961.rs b/tests/ui/type-alias-impl-trait/issue-57961.rs
index 4aa5966ff..61af7a0f6 100644
--- a/tests/ui/type-alias-impl-trait/issue-57961.rs
+++ b/tests/ui/type-alias-impl-trait/issue-57961.rs
@@ -11,8 +11,8 @@ impl Foo for () {
//~^ ERROR expected `IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32`
}
-fn incoherent() {
- let f: X = 22_i32;
+fn incoherent() -> X {
+ 22_i32
}
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-60564.rs b/tests/ui/type-alias-impl-trait/issue-60564.rs
index c2f4c3708..48bd70bcc 100644
--- a/tests/ui/type-alias-impl-trait/issue-60564.rs
+++ b/tests/ui/type-alias-impl-trait/issue-60564.rs
@@ -17,6 +17,7 @@ where
{
type BitsIter = IterBitsIter<T, E, u8>;
fn iter_bits(self, n: u8) -> Self::BitsIter {
+ //~^ ERROR non-defining opaque type use
(0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap())
//~^ ERROR expected generic type parameter, found `u8`
}
diff --git a/tests/ui/type-alias-impl-trait/issue-60564.stderr b/tests/ui/type-alias-impl-trait/issue-60564.stderr
index f8fdb004d..d42495e93 100644
--- a/tests/ui/type-alias-impl-trait/issue-60564.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-60564.stderr
@@ -1,5 +1,17 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/issue-60564.rs:19:34
+ |
+LL | fn iter_bits(self, n: u8) -> Self::BitsIter {
+ | ^^^^^^^^^^^^^^ argument `u8` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/issue-60564.rs:8:30
+ |
+LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
error[E0792]: expected generic type parameter, found `u8`
- --> $DIR/issue-60564.rs:20:9
+ --> $DIR/issue-60564.rs:21:9
|
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| - this generic parameter must be used with a generic type parameter
@@ -7,6 +19,6 @@ LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
LL | (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to previous error
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs b/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs
index 7414611a7..ddea7aeb6 100644
--- a/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs
+++ b/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs
@@ -8,6 +8,9 @@
pub type Closure = impl FnOnce();
-fn main() {
+fn bop() -> Closure {
|| -> Closure { || () };
+ panic!()
}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
index b91cbce37..7b3e9e124 100644
--- a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
+++ b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
@@ -11,7 +11,9 @@ type T = impl Sized;
fn take(_: fn() -> T) {}
-fn main() {
+fn bop(_: T) {
take(|| {});
take(|| {});
}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs
index 5e0a82a72..9dcdb5785 100644
--- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs
+++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs
@@ -7,7 +7,8 @@ trait Trait<T> {}
type Alias<'a, U> = impl Trait<U>;
fn f<'a>() -> Alias<'a, ()> {}
-//~^ ERROR expected generic type parameter, found `()`
+//~^ ERROR non-defining opaque type use
+//~| ERROR expected generic type parameter, found `()`
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr
index 271743a40..085bffe90 100644
--- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr
@@ -1,3 +1,15 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/issue-68368-non-defining-use-2.rs:9:15
+ |
+LL | fn f<'a>() -> Alias<'a, ()> {}
+ | ^^^^^^^^^^^^^ argument `()` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/issue-68368-non-defining-use-2.rs:7:21
+ |
+LL | type Alias<'a, U> = impl Trait<U>;
+ | ^^^^^^^^^^^^^
+
error[E0792]: expected generic type parameter, found `()`
--> $DIR/issue-68368-non-defining-use-2.rs:9:29
|
@@ -7,6 +19,6 @@ LL |
LL | fn f<'a>() -> Alias<'a, ()> {}
| ^^
-error: aborting due to previous error
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs
index 3b32260c9..dfe2ee820 100644
--- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs
+++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs
@@ -8,6 +8,7 @@ type Alias<'a, U> = impl Trait<U>;
fn f<'a>() -> Alias<'a, ()> {}
//~^ ERROR expected generic type parameter, found `()`
+//~| ERROR non-defining opaque type use
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr
index 4d9a8d6ee..ea704ffff 100644
--- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr
@@ -1,3 +1,15 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/issue-68368-non-defining-use.rs:9:15
+ |
+LL | fn f<'a>() -> Alias<'a, ()> {}
+ | ^^^^^^^^^^^^^ argument `()` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/issue-68368-non-defining-use.rs:7:21
+ |
+LL | type Alias<'a, U> = impl Trait<U>;
+ | ^^^^^^^^^^^^^
+
error[E0792]: expected generic type parameter, found `()`
--> $DIR/issue-68368-non-defining-use.rs:9:29
|
@@ -7,6 +19,6 @@ LL |
LL | fn f<'a>() -> Alias<'a, ()> {}
| ^^
-error: aborting due to previous error
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs
index 7657fe2fb..a0f8e48e2 100644
--- a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs
+++ b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs
@@ -1,4 +1,6 @@
-// Regression test for #69136
+//! Regression test for #69136
+//! This test checks that the unknown lifetime `'a` doesn't cause
+//! ICEs after emitting the error.
#![feature(type_alias_impl_trait)]
@@ -17,7 +19,6 @@ impl<T> WithAssoc<T> for () {
type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
//~^ ERROR use of undeclared lifetime name `'a`
-fn my_fun() -> Return<()> {}
-//~^ ERROR expected generic type parameter, found `()`
+fn my_fun<T>() -> Return<T> {}
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr
index d1250786d..b7af3f06d 100644
--- a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr
@@ -1,5 +1,5 @@
error[E0261]: use of undeclared lifetime name `'a`
- --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:65
+ --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:19:65
|
LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
| ^^ undeclared lifetime
@@ -14,16 +14,6 @@ help: consider introducing lifetime `'a` here
LL | type Return<'a, A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
| +++
-error[E0792]: expected generic type parameter, found `()`
- --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27
- |
-LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
- | - this generic parameter must be used with a generic type parameter
-...
-LL | fn my_fun() -> Return<()> {}
- | ^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
-Some errors have detailed explanations: E0261, E0792.
-For more information about an error, try `rustc --explain E0261`.
+For more information about this error, try `rustc --explain E0261`.
diff --git a/tests/ui/type-alias-impl-trait/issue-70121.rs b/tests/ui/type-alias-impl-trait/issue-70121.rs
index dff0d89d4..bfd8d8872 100644
--- a/tests/ui/type-alias-impl-trait/issue-70121.rs
+++ b/tests/ui/type-alias-impl-trait/issue-70121.rs
@@ -1,5 +1,3 @@
-// check-pass
-
#![feature(type_alias_impl_trait)]
pub type Successors<'a> = impl Iterator<Item = &'a ()>;
@@ -17,6 +15,7 @@ impl<'a> Tr for &'a () {
}
pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
+ //~^ ERROR item constrains opaque type that is not in its signature
None.into_iter()
}
diff --git a/tests/ui/type-alias-impl-trait/issue-70121.stderr b/tests/ui/type-alias-impl-trait/issue-70121.stderr
new file mode 100644
index 000000000..30c3ddd86
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/issue-70121.stderr
@@ -0,0 +1,15 @@
+error: item constrains opaque type that is not in its signature
+ --> $DIR/issue-70121.rs:17:24
+ |
+LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this item must mention the opaque type in its signature in order to be able to register hidden types
+note: this item must mention the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/issue-70121.rs:17:8
+ |
+LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item {
+ | ^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
index b97e444c6..386b77d4d 100644
--- a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
+++ b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs
@@ -1,6 +1,8 @@
// Regression test for issue #76202
// Tests that we don't ICE when we have a trait impl on a TAIT.
+// revisions: current next
+//[next] compile-flags: -Ztrait-solver=next
// check-pass
#![feature(type_alias_impl_trait)]
diff --git a/tests/ui/type-alias-impl-trait/issue-77179.rs b/tests/ui/type-alias-impl-trait/issue-77179.rs
index 8d818d4a3..e7b04a489 100644
--- a/tests/ui/type-alias-impl-trait/issue-77179.rs
+++ b/tests/ui/type-alias-impl-trait/issue-77179.rs
@@ -2,7 +2,7 @@
#![feature(type_alias_impl_trait)]
-type Pointer<T> = impl std::ops::Deref<Target=T>;
+type Pointer<T> = impl std::ops::Deref<Target = T>;
fn test() -> Pointer<_> {
//~^ ERROR: the placeholder `_` is not allowed within types
diff --git a/tests/ui/type-alias-impl-trait/multi-error.rs b/tests/ui/type-alias-impl-trait/multi-error.rs
new file mode 100644
index 000000000..b5ff06572
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/multi-error.rs
@@ -0,0 +1,23 @@
+//! This test checks that we don't follow up
+//! with type mismatch errors of opaque types
+//! with their hidden types if we failed the
+//! defining scope check at the signature level.
+
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo {
+ type Bar<T>;
+ type Baz;
+ fn foo() -> (Self::Bar<u32>, Self::Baz);
+}
+
+impl Foo for () {
+ type Bar<T> = impl Sized;
+ type Baz = impl Sized;
+ fn foo() -> (Self::Bar<u32>, Self::Baz) {
+ //~^ ERROR non-defining opaque type use
+ ((), ())
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/multi-error.stderr b/tests/ui/type-alias-impl-trait/multi-error.stderr
new file mode 100644
index 000000000..b2de2effe
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/multi-error.stderr
@@ -0,0 +1,15 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/multi-error.rs:17:17
+ |
+LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/multi-error.rs:15:19
+ |
+LL | type Bar<T> = impl Sized;
+ | ^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs
index 9ae2c34b9..da845e861 100644
--- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs
+++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs
@@ -8,7 +8,6 @@ type X<A, B> = impl Into<&'static A>;
fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
- //~| ERROR concrete type differs from previous defining opaque type use
(a, a)
}
diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
index 0d24d42ba..66a6b0bbf 100644
--- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
+++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr
@@ -10,15 +10,6 @@ help: consider introducing a `where` clause, but there might be an alternative b
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) where &'static B: From<&A> {
| ++++++++++++++++++++++++++
-error: concrete type differs from previous defining opaque type use
- --> $DIR/multiple-def-uses-in-one-fn.rs:9:45
- |
-LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
- | ^^^^^^^^^^^^^^^^^^
- | |
- | expected `&B`, got `&A`
- | this expression supplies two conflicting concrete types for the same opaque type
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference2.stderr
index f4d96038d..dccf84362 100644
--- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.stderr
+++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.stderr
@@ -8,8 +8,8 @@ LL | ()
| -- return type was inferred to be `()` here
|
= help: the following other types implement trait `Foo<A>`:
- <() as Foo<()>>
<() as Foo<u32>>
+ <() as Foo<()>>
error: aborting due to previous error
diff --git a/tests/ui/type-alias-impl-trait/nested_in_closure.rs b/tests/ui/type-alias-impl-trait/nested_in_closure.rs
new file mode 100644
index 000000000..362f3d53e
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/nested_in_closure.rs
@@ -0,0 +1,17 @@
+#![feature(type_alias_impl_trait)]
+// check-pass
+
+fn main() {
+ let x = || {
+ type Tait = impl Sized;
+ let y: Tait = ();
+ };
+
+ let y = || {
+ type Tait = impl std::fmt::Debug;
+ let y: Tait = ();
+ y
+ };
+ let mut z = y();
+ z = ();
+}
diff --git a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
index 60b6e1aac..07607516c 100644
--- a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
+++ b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs
@@ -10,11 +10,11 @@ mod my_mod {
5i32
}
- pub fn get_foot() -> Foot {
+ pub fn get_foot(_: Foo) -> Foot {
get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type
}
}
fn main() {
- let _: my_mod::Foot = my_mod::get_foot();
+ let _: my_mod::Foot = my_mod::get_foot(my_mod::get_foo());
}
diff --git a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr
index ae03a5b3e..863282a0f 100644
--- a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr
+++ b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr
@@ -11,6 +11,11 @@ LL | let _: &str = bomp();
|
= note: expected reference `&str`
found opaque type `Boo`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/no_revealing_outside_defining_module.rs:14:4
+ |
+LL | fn bomp2() {
+ | ^^^^^
error[E0308]: mismatched types
--> $DIR/no_revealing_outside_defining_module.rs:19:5
@@ -25,6 +30,11 @@ LL | ""
|
= note: expected opaque type `Boo`
found reference `&'static str`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/no_revealing_outside_defining_module.rs:18:4
+ |
+LL | fn bomp() -> boo::Boo {
+ | ^^^^
error: aborting due to 2 previous errors
diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.rs b/tests/ui/type-alias-impl-trait/non-defining-method.rs
new file mode 100644
index 000000000..2f4a7052f
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/non-defining-method.rs
@@ -0,0 +1,21 @@
+//! This test checks that we don't follow up
+//! with type mismatch errors of opaque types
+//! with their hidden types if we failed the
+//! defining scope check at the signature level.
+
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo {
+ type Bar<T>;
+ fn foo() -> Self::Bar<u32>;
+ fn bar<T>() -> Self::Bar<T>;
+}
+
+impl Foo for () {
+ type Bar<T> = impl Sized;
+ fn foo() -> Self::Bar<u32> {}
+ //~^ ERROR non-defining opaque type use
+ fn bar<T>() -> Self::Bar<T> {}
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.stderr b/tests/ui/type-alias-impl-trait/non-defining-method.stderr
new file mode 100644
index 000000000..ed5590f9d
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/non-defining-method.stderr
@@ -0,0 +1,15 @@
+error[E0792]: non-defining opaque type use in defining scope
+ --> $DIR/non-defining-method.rs:16:17
+ |
+LL | fn foo() -> Self::Bar<u32> {}
+ | ^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
+ |
+note: for this opaque type
+ --> $DIR/non-defining-method.rs:15:19
+ |
+LL | type Bar<T> = impl Sized;
+ | ^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr
new file mode 100644
index 000000000..dd2737c70
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr
@@ -0,0 +1,55 @@
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/normalize-hidden-types.rs:25:20
+ |
+LL | fn define() -> Opaque {
+ | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
+ |
+note: previous use here
+ --> $DIR/normalize-hidden-types.rs:27:9
+ |
+LL | dyn_hoops::<_>(0)
+ | ^^^^^^^^^^^^^^^^^
+
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/normalize-hidden-types.rs:34:22
+ |
+LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
+ | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
+ |
+note: previous use here
+ --> $DIR/normalize-hidden-types.rs:34:31
+ |
+LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
+ | ^^^^^^^^^^^^^^^^^
+
+error[E0308]: mismatched types
+ --> $DIR/normalize-hidden-types.rs:44:25
+ |
+LL | type Opaque = impl Sized;
+ | ---------- the expected opaque type
+...
+LL | let _: Opaque = dyn_hoops::<u8>(0);
+ | ------ ^^^^^^^^^^^^^^^^^^ expected opaque type, found `*const dyn FnOnce(())`
+ | |
+ | expected due to this
+ |
+ = note: expected opaque type `typeck::Opaque`
+ found raw pointer `*const (dyn FnOnce(()) + 'static)`
+ = help: consider constraining the associated type `<u8 as Trait>::Gat<'_>` to `()` or calling a method that returns `<u8 as Trait>::Gat<'_>`
+ = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/normalize-hidden-types.rs:54:25
+ |
+LL | let _: Opaque = dyn_hoops::<_>(0);
+ | ^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
+ |
+note: previous use here
+ --> $DIR/normalize-hidden-types.rs:56:9
+ |
+LL | None
+ | ^^^^
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs
new file mode 100644
index 000000000..8d8054644
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs
@@ -0,0 +1,60 @@
+// Regression test for #112691
+//
+// revisions: current next
+// [next] compile-flags: -Ztrait-solver=next
+// [next] check-pass
+// [current]: known-bug: #112691
+
+#![feature(type_alias_impl_trait)]
+
+trait Trait {
+ type Gat<'lt>;
+}
+
+impl Trait for u8 {
+ type Gat<'lt> = ();
+}
+
+fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
+ loop {}
+}
+
+mod typeof_1 {
+ use super::*;
+ type Opaque = impl Sized;
+ fn define() -> Opaque {
+ //[current]~^ ERROR concrete type differs
+ dyn_hoops::<_>(0)
+ }
+}
+
+mod typeof_2 {
+ use super::*;
+ type Opaque = impl Sized;
+ fn define_1() -> Opaque { dyn_hoops::<_>(0) }
+ //[current]~^ ERROR concrete type differs
+ fn define_2() -> Opaque { dyn_hoops::<u8>(0) }
+}
+
+mod typeck {
+ use super::*;
+ type Opaque = impl Sized;
+ fn define() -> Option<Opaque> {
+ let _: Opaque = dyn_hoops::<_>(0);
+ let _: Opaque = dyn_hoops::<u8>(0);
+ //[current]~^ ERROR mismatched types
+ None
+ }
+}
+
+mod borrowck {
+ use super::*;
+ type Opaque = impl Sized;
+ fn define() -> Option<Opaque> {
+ let _: Opaque = dyn_hoops::<_>(0);
+ //[current]~^ ERROR concrete type differs
+ None
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs
new file mode 100644
index 000000000..131f8d999
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs
@@ -0,0 +1,33 @@
+#![feature(impl_trait_in_assoc_type)]
+
+trait Foo<T> {
+ type Assoc;
+
+ fn test() -> u32;
+}
+
+struct DefinesOpaque;
+impl Foo<DefinesOpaque> for () {
+ type Assoc = impl Sized;
+
+ // This test's return type is `u32`, *not* the opaque that is defined above.
+ // Previously we were only checking that the self type of the assoc matched,
+ // but this doesn't account for other impls with different trait substs.
+ fn test() -> <() as Foo<NoOpaques>>::Assoc {
+ let _: <Self as Foo<DefinesOpaque>>::Assoc = "";
+ //~^ ERROR mismatched types
+
+ 1
+ }
+}
+
+struct NoOpaques;
+impl Foo<NoOpaques> for () {
+ type Assoc = u32;
+
+ fn test() -> u32 {
+ 1
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr
new file mode 100644
index 000000000..a621bb519
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr
@@ -0,0 +1,22 @@
+error[E0308]: mismatched types
+ --> $DIR/not-matching-trait-refs-isnt-defining.rs:17:54
+ |
+LL | type Assoc = impl Sized;
+ | ---------- the expected opaque type
+...
+LL | let _: <Self as Foo<DefinesOpaque>>::Assoc = "";
+ | ----------------------------------- ^^ expected opaque type, found `&str`
+ | |
+ | expected due to this
+ |
+ = note: expected opaque type `<() as Foo<DefinesOpaque>>::Assoc`
+ found reference `&'static str`
+note: this item must have the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/not-matching-trait-refs-isnt-defining.rs:16:8
+ |
+LL | fn test() -> <() as Foo<NoOpaques>>::Assoc {
+ | ^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/obligation_ice.rs b/tests/ui/type-alias-impl-trait/obligation_ice.rs
new file mode 100644
index 000000000..5aef04ff1
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/obligation_ice.rs
@@ -0,0 +1,17 @@
+#![feature(type_alias_impl_trait)]
+// check-pass
+
+use std::iter::{once, Chain};
+
+trait Trait<'a, 'b: 'a> {}
+
+impl<'a, 'b: 'a, T> Trait<'a, 'b> for std::iter::Cloned<T> {}
+
+type I<'a, 'b: 'a, A: Trait<'a, 'b>> = Chain<A, impl Iterator<Item = &'static str>>;
+fn test2<'a, 'b, A: Trait<'a, 'b> + Iterator<Item = &'static str>>(x: A) -> I<'a, 'b, A> {
+ x.chain(once("5"))
+}
+
+fn main() {
+ assert_eq!(vec!["1", "3", "5"], test2(["1", "3"].iter().cloned()).collect::<Vec<_>>());
+}
diff --git a/tests/ui/type-alias-impl-trait/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs
new file mode 100644
index 000000000..aa092f6f8
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/privacy.rs
@@ -0,0 +1,8 @@
+#![feature(type_alias_impl_trait)]
+
+type Foo = (impl Sized, u8);
+pub fn foo() -> Foo {
+ //~^ ERROR private type alias `Foo` in public interface
+ (42, 42)
+}
+fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/privacy.stderr b/tests/ui/type-alias-impl-trait/privacy.stderr
new file mode 100644
index 000000000..e8c6039cd
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/privacy.stderr
@@ -0,0 +1,11 @@
+error[E0446]: private type alias `Foo` in public interface
+ --> $DIR/privacy.rs:4:1
+ |
+LL | type Foo = (impl Sized, u8);
+ | -------- `Foo` declared as private
+LL | pub fn foo() -> Foo {
+ | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0446`.
diff --git a/tests/ui/type-alias-impl-trait/reveal_local.rs b/tests/ui/type-alias-impl-trait/reveal_local.rs
index 7ecb55353..7943bb240 100644
--- a/tests/ui/type-alias-impl-trait/reveal_local.rs
+++ b/tests/ui/type-alias-impl-trait/reveal_local.rs
@@ -4,22 +4,28 @@ use std::fmt::Debug;
type Foo = impl Debug;
//~^ ERROR cycle detected
+//~| ERROR cycle detected
+//~| ERROR cycle detected
-fn is_send<T: Send>() { }
+fn is_send<T: Send>() {}
fn not_good() {
// Error: this function does not constrain `Foo` to any particular
// hidden type, so it cannot rely on `Send` being true.
is_send::<Foo>();
+ //~^ ERROR: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
}
-fn not_gooder() {
+fn not_gooder() -> Foo {
// Constrain `Foo = u32`
let x: Foo = 22_u32;
// while we could know this from the hidden type, it would
// need extra roundabout logic to support it.
is_send::<Foo>();
+ //~^ ERROR: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
+
+ x
}
fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/reveal_local.stderr b/tests/ui/type-alias-impl-trait/reveal_local.stderr
index 27fded333..0c5ef4a6f 100644
--- a/tests/ui/type-alias-impl-trait/reveal_local.stderr
+++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr
@@ -5,7 +5,7 @@ LL | type Foo = impl Debug;
| ^^^^^^^^^^
|
note: ...which requires type-checking `not_good`...
- --> $DIR/reveal_local.rs:13:5
+ --> $DIR/reveal_local.rs:15:5
|
LL | is_send::<Foo>();
| ^^^^^^^^^^^^^^
@@ -23,6 +23,98 @@ LL | |
LL | | fn main() {}
| |____________^
-error: aborting due to previous error
+error[E0391]: cycle detected when computing type of `Foo::{opaque#0}`
+ --> $DIR/reveal_local.rs:5:12
+ |
+LL | type Foo = impl Debug;
+ | ^^^^^^^^^^
+ |
+note: ...which requires type-checking `not_good`...
+ --> $DIR/reveal_local.rs:12:1
+ |
+LL | fn not_good() {
+ | ^^^^^^^^^^^^^
+ = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle
+note: cycle used when checking item types in top-level module
+ --> $DIR/reveal_local.rs:1:1
+ |
+LL | / #![feature(type_alias_impl_trait)]
+LL | |
+LL | | use std::fmt::Debug;
+LL | |
+... |
+LL | |
+LL | | fn main() {}
+ | |____________^
+
+error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
+ --> $DIR/reveal_local.rs:15:15
+ |
+LL | is_send::<Foo>();
+ | ^^^
+ |
+note: opaque type is declared here
+ --> $DIR/reveal_local.rs:5:12
+ |
+LL | type Foo = impl Debug;
+ | ^^^^^^^^^^
+note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
+ --> $DIR/reveal_local.rs:12:4
+ |
+LL | fn not_good() {
+ | ^^^^^^^^
+note: required by a bound in `is_send`
+ --> $DIR/reveal_local.rs:10:15
+ |
+LL | fn is_send<T: Send>() {}
+ | ^^^^ required by this bound in `is_send`
+
+error[E0391]: cycle detected when computing type of `Foo::{opaque#0}`
+ --> $DIR/reveal_local.rs:5:12
+ |
+LL | type Foo = impl Debug;
+ | ^^^^^^^^^^
+ |
+note: ...which requires type-checking `not_gooder`...
+ --> $DIR/reveal_local.rs:19:1
+ |
+LL | fn not_gooder() -> Foo {
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle
+note: cycle used when checking item types in top-level module
+ --> $DIR/reveal_local.rs:1:1
+ |
+LL | / #![feature(type_alias_impl_trait)]
+LL | |
+LL | | use std::fmt::Debug;
+LL | |
+... |
+LL | |
+LL | | fn main() {}
+ | |____________^
+
+error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
+ --> $DIR/reveal_local.rs:25:15
+ |
+LL | is_send::<Foo>();
+ | ^^^
+ |
+note: opaque type is declared here
+ --> $DIR/reveal_local.rs:5:12
+ |
+LL | type Foo = impl Debug;
+ | ^^^^^^^^^^
+note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
+ --> $DIR/reveal_local.rs:19:4
+ |
+LL | fn not_gooder() -> Foo {
+ | ^^^^^^^^^^
+note: required by a bound in `is_send`
+ --> $DIR/reveal_local.rs:10:15
+ |
+LL | fn is_send<T: Send>() {}
+ | ^^^^ required by this bound in `is_send`
+
+error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.rs b/tests/ui/type-alias-impl-trait/self-referential-3.rs
index d40715717..18f09b548 100644
--- a/tests/ui/type-alias-impl-trait/self-referential-3.rs
+++ b/tests/ui/type-alias-impl-trait/self-referential-3.rs
@@ -1,9 +1,9 @@
-// run-pass
#![feature(type_alias_impl_trait)]
type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + std::fmt::Debug;
fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
+ //~^ ERROR can't compare `&i32` with `Bar<'a, 'b>`
i
}
diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.stderr b/tests/ui/type-alias-impl-trait/self-referential-3.stderr
new file mode 100644
index 000000000..4155a114b
--- /dev/null
+++ b/tests/ui/type-alias-impl-trait/self-referential-3.stderr
@@ -0,0 +1,15 @@
+error[E0277]: can't compare `&i32` with `Bar<'a, 'b>`
+ --> $DIR/self-referential-3.rs:5:31
+ |
+LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
+ | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'a, 'b>`
+LL |
+LL | i
+ | - return type was inferred to be `&i32` here
+ |
+ = help: the trait `PartialEq<Bar<'a, 'b>>` is not implemented for `&i32`
+ = help: the trait `PartialEq` is implemented for `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/type-alias-impl-trait/self-referential.rs b/tests/ui/type-alias-impl-trait/self-referential.rs
index 3ff5406a3..34b7c24df 100644
--- a/tests/ui/type-alias-impl-trait/self-referential.rs
+++ b/tests/ui/type-alias-impl-trait/self-referential.rs
@@ -10,7 +10,7 @@ fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
type Foo<'a, 'b> = (i32, impl PartialEq<Foo<'a, 'b>> + std::fmt::Debug);
fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> {
- //~^ ERROR can't compare `&i32` with `(i32, &i32)`
+ //~^ ERROR can't compare `&i32` with `(i32, Foo<'a, 'b>::{opaque#0})`
(42, i)
}
diff --git a/tests/ui/type-alias-impl-trait/self-referential.stderr b/tests/ui/type-alias-impl-trait/self-referential.stderr
index aff489d70..9a17d495b 100644
--- a/tests/ui/type-alias-impl-trait/self-referential.stderr
+++ b/tests/ui/type-alias-impl-trait/self-referential.stderr
@@ -10,16 +10,16 @@ LL | i
= help: the trait `PartialEq<Bar<'b, 'a>>` is not implemented for `&i32`
= help: the trait `PartialEq` is implemented for `i32`
-error[E0277]: can't compare `&i32` with `(i32, &i32)`
+error[E0277]: can't compare `&i32` with `(i32, Foo<'a, 'b>::{opaque#0})`
--> $DIR/self-referential.rs:12:31
|
LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> {
- | ^^^^^^^^^^^ no implementation for `&i32 == (i32, &i32)`
+ | ^^^^^^^^^^^ no implementation for `&i32 == (i32, Foo<'a, 'b>::{opaque#0})`
LL |
LL | (42, i)
| ------- return type was inferred to be `(i32, &i32)` here
|
- = help: the trait `PartialEq<(i32, &i32)>` is not implemented for `&i32`
+ = help: the trait `PartialEq<(i32, Foo<'a, 'b>::{opaque#0})>` is not implemented for `&i32`
= help: the trait `PartialEq` is implemented for `i32`
error[E0277]: can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})`
diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
index 07c891f06..4e7388517 100644
--- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
+++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs
@@ -4,20 +4,20 @@
// Regression test for issue #61863
-pub trait MyTrait {}
+trait MyTrait {}
#[derive(Debug)]
-pub struct MyStruct {
+struct MyStruct {
v: u64,
}
impl MyTrait for MyStruct {}
-pub fn bla() -> TE {
+fn bla() -> TE {
return MyStruct { v: 1 };
}
-pub fn bla2() -> TE {
+fn bla2() -> TE {
bla()
}
diff --git a/tests/ui/type-alias-impl-trait/type_of_a_let.rs b/tests/ui/type-alias-impl-trait/type_of_a_let.rs
index 4e9d1788b..361611715 100644
--- a/tests/ui/type-alias-impl-trait/type_of_a_let.rs
+++ b/tests/ui/type-alias-impl-trait/type_of_a_let.rs
@@ -5,16 +5,16 @@ use std::fmt::Debug;
type Foo = impl Debug;
-fn foo1() -> u32 {
+fn foo1() -> (u32, Foo) {
let x: Foo = 22_u32;
- x
+ (x, todo!())
}
-fn foo2() -> u32 {
+fn foo2() -> (u32, Foo) {
let x: Foo = 22_u32;
let y: Foo = x;
same_type((x, y)); //~ ERROR use of moved value
- y //~ ERROR use of moved value
+ (y, todo!()) //~ ERROR use of moved value
}
fn same_type<T>(x: (T, T)) {}
diff --git a/tests/ui/type-alias-impl-trait/type_of_a_let.stderr b/tests/ui/type-alias-impl-trait/type_of_a_let.stderr
index 1dabe4586..7d7cad874 100644
--- a/tests/ui/type-alias-impl-trait/type_of_a_let.stderr
+++ b/tests/ui/type-alias-impl-trait/type_of_a_let.stderr
@@ -9,14 +9,14 @@ LL | same_type((x, y));
| ^ value used here after move
error[E0382]: use of moved value: `y`
- --> $DIR/type_of_a_let.rs:17:5
+ --> $DIR/type_of_a_let.rs:17:6
|
LL | let y: Foo = x;
| - move occurs because `y` has type `Foo`, which does not implement the `Copy` trait
LL | same_type((x, y));
| - value moved here
-LL | y
- | ^ value used here after move
+LL | (y, todo!())
+ | ^ value used here after move
error: aborting due to 2 previous errors