-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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,27 @@ | ||
//! Check that projections will constrain opaque types while looking for | ||
//! matching impls. | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
//@check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
struct Foo; | ||
|
||
type Bar = impl Sized; | ||
|
||
trait Trait<T> { | ||
type Assoc: Default; | ||
} | ||
|
||
impl Trait<()> for Foo { | ||
type Assoc = u32; | ||
} | ||
|
||
fn bop(_: Bar) { | ||
let x = <Foo as Trait<Bar>>::Assoc::default(); | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/type-alias-impl-trait/constrain_in_projection2.current.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,19 @@ | ||
error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>` | ||
--> $DIR/constrain_in_projection2.rs:27:14 | ||
| | ||
LL | let x = <Foo as Trait<Bar>>::Assoc::default(); | ||
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc` | ||
| | ||
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found | ||
--> $DIR/constrain_in_projection2.rs:18:1 | ||
| | ||
LL | impl Trait<()> for Foo { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | impl Trait<u32> for Foo { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0283`. |
19 changes: 19 additions & 0 deletions
19
tests/ui/type-alias-impl-trait/constrain_in_projection2.next.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,19 @@ | ||
error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>` | ||
--> $DIR/constrain_in_projection2.rs:27:14 | ||
| | ||
LL | let x = <Foo as Trait<Bar>>::Assoc::default(); | ||
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc` | ||
| | ||
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found | ||
--> $DIR/constrain_in_projection2.rs:18:1 | ||
| | ||
LL | impl Trait<()> for Foo { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | impl Trait<u32> for Foo { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0283`. |
31 changes: 31 additions & 0 deletions
31
tests/ui/type-alias-impl-trait/constrain_in_projection2.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,31 @@ | ||
//! Check that projections will constrain opaque types while looking for | ||
//! matching impls and error if ambiguous. | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
struct Foo; | ||
|
||
type Bar = impl Sized; | ||
|
||
trait Trait<T> { | ||
type Assoc: Default; | ||
} | ||
|
||
impl Trait<()> for Foo { | ||
type Assoc = u32; | ||
} | ||
|
||
impl Trait<u32> for Foo { | ||
type Assoc = u32; | ||
} | ||
|
||
fn bop(_: Bar) { | ||
let x = <Foo as Trait<Bar>>::Assoc::default(); | ||
//~^ ERROR: cannot satisfy `Foo: Trait<Bar>` | ||
} | ||
|
||
fn main() {} |