Skip to content

Commit

Permalink
add tests for pyella regression
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 2, 2024
1 parent d361fb6 commit ef7071d
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/ui/coherence/super-traits/super-trait-knowable-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Added in #124532. While `(): Super` is knowable, `(): Sub<?t>` is not.
//
// We therefore elaborate super trait bounds in the implicit negative
// overlap check.

trait Super {}
trait Sub<T>: Super {}

trait Overlap<T> {}
impl<T, U: Sub<T>> Overlap<T> for U {}
impl<T> Overlap<T> for () {}
//~^ ERROR conflicting implementations of trait `Overlap<_>` for type `()`

fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/coherence/super-traits/super-trait-knowable-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()`
--> $DIR/super-trait-knowable-1.rs:11:1
|
LL | impl<T, U: Sub<T>> Overlap<T> for U {}
| ----------------------------------- first implementation here
LL | impl<T> Overlap<T> for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
|
= note: downstream crates may implement trait `Sub<_>` for type `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
29 changes: 29 additions & 0 deletions tests/ui/coherence/super-traits/super-trait-knowable-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// A regression test for pyella-0.1.5 which broke when
// enabling the new solver in coherence.
//
// `Tensor: TensorValue` is knowable while `Tensor: TensorOp<?t2>`
// may be implemented downstream. We previously didn't check the
// super trait bound in coherence, causing these impls to overlap.
//
// However, we did fail to normalize `<Tensor as TensorValue::Unmasked`
// which caused the old solver to emit a `Tensor: TensorValue` goal in
// `fn normalize_to_error` which then failed, causing this test to pass.

pub trait TensorValue {
type Unmasked;
}

trait TensorCompare<T> {}
pub trait TensorOp<T>: TensorValue {}

pub struct Tensor;
impl<T2> TensorCompare<T2> for Tensor {}
impl<T1, T2> TensorCompare<T2> for T1
//~^ ERROR conflicting implementations
where
T1: TensorOp<T2>,
T1::Unmasked: Sized,
{}


fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/coherence/super-traits/super-trait-knowable-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0119]: conflicting implementations of trait `TensorCompare<_>` for type `Tensor`
--> $DIR/super-trait-knowable-2.rs:21:1
|
LL | impl<T2> TensorCompare<T2> for Tensor {}
| ------------------------------------- first implementation here
LL | / impl<T1, T2> TensorCompare<T2> for T1
LL | |
LL | | where
LL | | T1: TensorOp<T2>,
LL | | T1::Unmasked: Sized,
| |________________________^ conflicting implementation for `Tensor`
|
= note: downstream crates may implement trait `TensorOp<_>` for type `Tensor`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()`
--> $DIR/super-trait-knowable-nested.rs:19:1
|
LL | impl<T, U: Bound<T>> Overlap<T> for U {}
| ------------------------------------- first implementation here
LL | impl<T> Overlap<T> for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
|
= note: downstream crates may implement trait `Bound<_>` for type `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Overlap<_>` for type `()`
--> $DIR/super-trait-knowable-nested.rs:19:1
|
LL | impl<T, U: Bound<T>> Overlap<T> for U {}
| ------------------------------------- first implementation here
LL | impl<T> Overlap<T> for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
|
= note: downstream crates may implement trait `Bound<_>` for type `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
22 changes: 22 additions & 0 deletions tests/ui/coherence/super-traits/super-trait-knowable-nested.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Unlike in `super-trait-knowable-1.rs`, the knowable
// super trait bound is in a nested goal and we currently
// only elaborate in the root. This can, and should, be#
// changed in the future.

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

trait Super {}
trait Sub<T>: Super {}

trait Bound<T> {}

impl<T: Sub<T>, U> Bound<U> for T {}

trait Overlap<T> {}
impl<T, U: Bound<T>> Overlap<T> for U {}
impl<T> Overlap<T> for () {}
//~^ ERROR conflicting implementations of trait `Overlap<_>` for type `()`

fn main() {}

0 comments on commit ef7071d

Please sign in to comment.