mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Additional test demonstrating check for full trait ref
This commit is contained in:
parent
5344ed23fa
commit
c4cd607100
@ -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() {}
|
@ -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`.
|
Loading…
Reference in New Issue
Block a user