Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for walking order dependent opaque type behaviour #126337

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/ui/impl-trait/associated-type-undefine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![feature(impl_trait_in_assoc_type)]

trait Foo: Sized {
type Bar;
type Gat<T: Foo>;
fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>);
}

impl Foo for u32 {
type Bar = ();
type Gat<T: Foo> = ();
fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
((), ())
}
}

impl Foo for () {
type Bar = impl Sized;
type Gat<T: Foo> = <T as Foo>::Bar;
// Because we encounter `Gat<u32>` first, we never walk into another `Gat`
// again, thus missing the opaque type that we could be defining.
fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
((), ())
//~^ ERROR: mismatched types
}
}

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/impl-trait/associated-type-undefine.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0308]: mismatched types
--> $DIR/associated-type-undefine.rs:23:14
|
LL | type Bar = impl Sized;
| ---------- the expected opaque type
...
LL | ((), ())
| ^^ expected opaque type, found `()`
|
= note: expected opaque type `<() as Foo>::Bar`
found unit type `()`
note: this item must have the opaque type in its signature in order to be able to register hidden types
--> $DIR/associated-type-undefine.rs:22:8
|
LL | fn foo(self) -> (<Self as Foo>::Gat<u32>, <Self as Foo>::Gat<Self>) {
| ^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading