add test for assoc type mismatch in supertrait

This commit is contained in:
Lukas Markeffsky 2024-02-29 21:24:09 +01:00
parent 7606c13961
commit 6fa58be8f4
2 changed files with 229 additions and 0 deletions

View file

@ -0,0 +1,41 @@
trait Super {
type Assoc;
}
impl Super for () {
type Assoc = u8;
}
trait Sub: Super<Assoc = u16> {}
trait BoundOnSelf: Sub {}
impl BoundOnSelf for () {}
//~^ ERROR the trait bound `(): Sub` is not satisfied
//~| ERROR type mismatch resolving `<() as Super>::Assoc == u16`
trait BoundOnParam<T: Sub> {}
impl BoundOnParam<()> for () {}
//~^ ERROR the trait bound `(): Sub` is not satisfied
//~| ERROR type mismatch resolving `<() as Super>::Assoc == u16`
trait BoundOnAssoc {
type Assoc: Sub;
}
impl BoundOnAssoc for () {
type Assoc = ();
//~^ ERROR the trait bound `(): Sub` is not satisfied
//~| ERROR type mismatch resolving `<() as Super>::Assoc == u16`
}
trait BoundOnGat where Self::Assoc<u8>: Sub {
type Assoc<T>;
}
impl BoundOnGat for u8 {
//~^ ERROR type mismatch resolving `<() as Super>::Assoc == u16`
type Assoc<T> = ();
//~^ ERROR the trait bound `(): Sub` is not satisfied
}
fn trivial_bound() where (): Sub {}
//~^ ERROR the trait bound `(): Sub` is not satisfied
//~| ERROR type mismatch resolving `<() as Super>::Assoc == u16`
fn main() {}

View file

@ -0,0 +1,188 @@
error[E0277]: the trait bound `(): Sub` is not satisfied
--> $DIR/super-assoc-mismatch.rs:10:22
|
LL | impl BoundOnSelf for () {}
| ^^ the trait `Sub` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/super-assoc-mismatch.rs:7:1
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `BoundOnSelf`
--> $DIR/super-assoc-mismatch.rs:9:20
|
LL | trait BoundOnSelf: Sub {}
| ^^^ required by this bound in `BoundOnSelf`
error[E0271]: type mismatch resolving `<() as Super>::Assoc == u16`
--> $DIR/super-assoc-mismatch.rs:10:6
|
LL | impl BoundOnSelf for () {}
| ^^^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == u16`
|
note: expected this to be `u16`
--> $DIR/super-assoc-mismatch.rs:5:18
|
LL | type Assoc = u8;
| ^^
note: required for `()` to implement `Sub`
--> $DIR/super-assoc-mismatch.rs:7:7
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^
note: required by a bound in `BoundOnSelf`
--> $DIR/super-assoc-mismatch.rs:9:20
|
LL | trait BoundOnSelf: Sub {}
| ^^^ required by this bound in `BoundOnSelf`
error[E0277]: the trait bound `(): Sub` is not satisfied
--> $DIR/super-assoc-mismatch.rs:15:27
|
LL | impl BoundOnParam<()> for () {}
| ^^ the trait `Sub` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/super-assoc-mismatch.rs:7:1
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `BoundOnParam`
--> $DIR/super-assoc-mismatch.rs:14:23
|
LL | trait BoundOnParam<T: Sub> {}
| ^^^ required by this bound in `BoundOnParam`
error[E0271]: type mismatch resolving `<() as Super>::Assoc == u16`
--> $DIR/super-assoc-mismatch.rs:15:6
|
LL | impl BoundOnParam<()> for () {}
| ^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == u16`
|
note: expected this to be `u16`
--> $DIR/super-assoc-mismatch.rs:5:18
|
LL | type Assoc = u8;
| ^^
note: required for `()` to implement `Sub`
--> $DIR/super-assoc-mismatch.rs:7:7
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^
note: required by a bound in `BoundOnParam`
--> $DIR/super-assoc-mismatch.rs:14:23
|
LL | trait BoundOnParam<T: Sub> {}
| ^^^ required by this bound in `BoundOnParam`
error[E0277]: the trait bound `(): Sub` is not satisfied
--> $DIR/super-assoc-mismatch.rs:23:18
|
LL | type Assoc = ();
| ^^ the trait `Sub` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/super-assoc-mismatch.rs:7:1
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `BoundOnAssoc::Assoc`
--> $DIR/super-assoc-mismatch.rs:20:17
|
LL | type Assoc: Sub;
| ^^^ required by this bound in `BoundOnAssoc::Assoc`
error[E0271]: type mismatch resolving `<() as Super>::Assoc == u16`
--> $DIR/super-assoc-mismatch.rs:23:18
|
LL | type Assoc = ();
| ^^ type mismatch resolving `<() as Super>::Assoc == u16`
|
note: expected this to be `u16`
--> $DIR/super-assoc-mismatch.rs:5:18
|
LL | type Assoc = u8;
| ^^
note: required for `<() as BoundOnAssoc>::Assoc` to implement `Sub`
--> $DIR/super-assoc-mismatch.rs:7:7
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^
note: required by a bound in `BoundOnAssoc::Assoc`
--> $DIR/super-assoc-mismatch.rs:20:17
|
LL | type Assoc: Sub;
| ^^^ required by this bound in `BoundOnAssoc::Assoc`
error[E0277]: the trait bound `(): Sub` is not satisfied
--> $DIR/super-assoc-mismatch.rs:33:21
|
LL | type Assoc<T> = ();
| ^^ the trait `Sub` is not implemented for `()`, which is required by `<u8 as BoundOnGat>::Assoc<u8>: Sub`
|
help: this trait has no implementations, consider adding one
--> $DIR/super-assoc-mismatch.rs:7:1
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `BoundOnGat`
--> $DIR/super-assoc-mismatch.rs:28:41
|
LL | trait BoundOnGat where Self::Assoc<u8>: Sub {
| ^^^ required by this bound in `BoundOnGat`
error[E0271]: type mismatch resolving `<() as Super>::Assoc == u16`
--> $DIR/super-assoc-mismatch.rs:31:6
|
LL | impl BoundOnGat for u8 {
| ^^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == u16`
|
note: expected this to be `u16`
--> $DIR/super-assoc-mismatch.rs:5:18
|
LL | type Assoc = u8;
| ^^
note: required for `<u8 as BoundOnGat>::Assoc<u8>` to implement `Sub`
--> $DIR/super-assoc-mismatch.rs:7:7
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^
note: required by a bound in `BoundOnGat`
--> $DIR/super-assoc-mismatch.rs:28:41
|
LL | trait BoundOnGat where Self::Assoc<u8>: Sub {
| ^^^ required by this bound in `BoundOnGat`
error[E0277]: the trait bound `(): Sub` is not satisfied
--> $DIR/super-assoc-mismatch.rs:37:26
|
LL | fn trivial_bound() where (): Sub {}
| ^^^^^^^ the trait `Sub` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/super-assoc-mismatch.rs:7:1
|
LL | trait Sub: Super<Assoc = u16> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: see issue #48214
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
error[E0271]: type mismatch resolving `<() as Super>::Assoc == u16`
--> $DIR/super-assoc-mismatch.rs:37:26
|
LL | fn trivial_bound() where (): Sub {}
| ^^^^^^^ type mismatch resolving `<() as Super>::Assoc == u16`
|
note: expected this to be `u8`
--> $DIR/super-assoc-mismatch.rs:5:18
|
LL | type Assoc = u8;
| ^^
= help: see issue #48214
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
error: aborting due to 10 previous errors
Some errors have detailed explanations: E0271, E0277.
For more information about an error, try `rustc --explain E0271`.