Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 17, 2024
1 parent d17e651 commit de10ccd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/ui/type-alias-impl-trait/constrain_in_projection.rs
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() {}
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`.
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 tests/ui/type-alias-impl-trait/constrain_in_projection2.rs
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() {}

0 comments on commit de10ccd

Please sign in to comment.