Skip to content

Commit

Permalink
Additional test demonstrating check for full trait ref
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 21, 2023
1 parent 5344ed2 commit c4cd607
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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:5
|
LL | fn test() -> <() as Foo<NoOpaques>>::Assoc {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

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

0 comments on commit c4cd607

Please sign in to comment.