add associated type bounds test

This commit is contained in:
Bastian Kauschke 2020-11-10 10:02:19 +01:00
parent dd78188185
commit a8310e202c
4 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,15 @@
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
--> $DIR/associated-type-bound-fail.rs:14:5
|
LL | type Assoc: Bar<N>;
| ------ required by this bound in `Foo::Assoc`
...
LL | type Assoc = u16;
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the following implementations were found:
<u16 as Bar<3_usize>>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,15 @@
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
--> $DIR/associated-type-bound-fail.rs:14:5
|
LL | type Assoc: Bar<N>;
| ------ required by this bound in `Foo::Assoc`
...
LL | type Assoc = u16;
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the following implementations were found:
<u16 as Bar<3_usize>>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,17 @@
// revisions: full min
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(min, feature(min_const_generics))]
trait Bar<const N: usize> {}
trait Foo<const N: usize> {
type Assoc: Bar<N>;
}
impl Bar<3> for u16 {}
impl<const N: usize> Foo<N> for i16 {
type Assoc = u16; //~ ERROR the trait bound `u16: Bar<N>`
}
fn main() {}

View File

@ -0,0 +1,24 @@
// run-pass
// revisions: full min
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(min, feature(min_const_generics))]
trait Bar<const N: usize> {}
trait Foo<const N: usize> {
type Assoc: Bar<N>;
}
impl<const N: usize> Bar<N> for u8 {}
impl Bar<3> for u16 {}
impl<const N: usize> Foo<N> for i8 {
type Assoc = u8;
}
impl Foo<3> for i16 {
type Assoc = u16;
}
fn main() {}