Skip to content

Commit

Permalink
add associated type bounds test
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 10, 2020
1 parent dd78188 commit a8310e2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.full.stderr
Original file line number Diff line number Diff line change
@@ -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`.
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.min.stderr
Original file line number Diff line number Diff line change
@@ -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`.
17 changes: 17 additions & 0 deletions src/test/ui/const-generics/associated-type-bound-fail.rs
Original file line number Diff line number Diff line change
@@ -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() {}
24 changes: 24 additions & 0 deletions src/test/ui/const-generics/associated-type-bound.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit a8310e2

Please sign in to comment.