-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional test demonstrating check for full trait ref
- Loading branch information
1 parent
5344ed2
commit c4cd607
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |