Skip to content

Commit

Permalink
add tests for rust-lang#114061
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Mar 21, 2024
1 parent fc22045 commit 876e8b0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/ui/coherence/aliases/ambig-assoc-type-with-bound-vars-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Regression test for #114061. We previously did
// not consider `for<'a> <T as WithAssoc<'a>>::Assoc: IsUnit`
// to be unknowable, even though the projection is
// ambiguous.
trait IsUnit {}
impl IsUnit for () {}


pub trait WithAssoc<'a> {
type Assoc;
}

// The two impls of `Trait` overlap
pub trait Trait {}
impl<T> Trait for T
where
T: 'static,
for<'a> T: WithAssoc<'a>,
for<'a> <T as WithAssoc<'a>>::Assoc: IsUnit,
{
}
impl<T> Trait for Box<T> {}
//~^ ERROR conflicting implementations of trait `Trait`

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0119]: conflicting implementations of trait `Trait` for type `Box<_>`
--> $DIR/ambig-assoc-type-with-bound-vars-1.rs:22:1
|
LL | / impl<T> Trait for T
LL | | where
LL | | T: 'static,
LL | | for<'a> T: WithAssoc<'a>,
LL | | for<'a> <T as WithAssoc<'a>>::Assoc: IsUnit,
| |________________________________________________- first implementation here
...
LL | impl<T> Trait for Box<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Box<_>`
|
= note: downstream crates may implement trait `WithAssoc<'a>` for type `std::boxed::Box<_>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
23 changes: 23 additions & 0 deletions tests/ui/coherence/aliases/ambig-assoc-type-with-bound-vars-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Another regression test for #114061.

pub trait WhereBound {}
impl WhereBound for () {}

pub trait WithAssoc<'a> {
type Assoc;
}

// The two impls of `Trait` overlap
pub trait Trait {}
impl<T> Trait for T
where
T: 'static,
for<'a> T: WithAssoc<'a>,
// This bound was previously treated as knowable
for<'a> Box<<T as WithAssoc<'a>>::Assoc>: WhereBound,
{
}
impl<T> Trait for Box<T> {}
//~^ ERROR conflicting implementations of trait `Trait`

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0119]: conflicting implementations of trait `Trait` for type `Box<_>`
--> $DIR/ambig-assoc-type-with-bound-vars-2.rs:20:1
|
LL | / impl<T> Trait for T
LL | | where
LL | | T: 'static,
LL | | for<'a> T: WithAssoc<'a>,
LL | | // This bound was previously treated as knowable
LL | | for<'a> Box<<T as WithAssoc<'a>>::Assoc>: WhereBound,
| |_________________________________________________________- first implementation here
...
LL | impl<T> Trait for Box<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Box<_>`
|
= note: downstream crates may implement trait `WithAssoc<'a>` for type `std::boxed::Box<_>`
= note: downstream crates may implement trait `WhereBound` for type `std::boxed::Box<<std::boxed::Box<_> as WithAssoc<'a>>::Assoc>`

error: aborting due to 1 previous error

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

0 comments on commit 876e8b0

Please sign in to comment.