Add test cases
This commit is contained in:
parent
523490e94a
commit
ee02c8e20a
4 changed files with 107 additions and 3 deletions
|
@ -0,0 +1,41 @@
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(const_fn_trait_bound)]
|
||||||
|
|
||||||
|
trait Bar {
|
||||||
|
fn bar() -> u8;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
#[default_method_body_is_const]
|
||||||
|
fn foo() -> u8 where Self: ~const Bar {
|
||||||
|
<Self as Bar>::bar() * 6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NonConst;
|
||||||
|
struct Const;
|
||||||
|
|
||||||
|
impl Bar for NonConst {
|
||||||
|
fn bar() -> u8 {
|
||||||
|
3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo for NonConst {}
|
||||||
|
|
||||||
|
impl const Bar for Const {
|
||||||
|
fn bar() -> u8 {
|
||||||
|
4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl const Foo for Const {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const ANS1: u8 = Const::foo();
|
||||||
|
let ans2 = NonConst::foo();
|
||||||
|
|
||||||
|
assert_eq!(ANS1 + ans2, 42);
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(const_fn_trait_bound)]
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn bar() where Self: ~const Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl Foo for S {
|
||||||
|
fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn baz<T: Foo>() {
|
||||||
|
T::bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn qux<T: ~const Foo>() {
|
||||||
|
T::bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -6,28 +6,35 @@ trait Bar {}
|
||||||
trait Foo {
|
trait Foo {
|
||||||
fn a();
|
fn a();
|
||||||
fn b() where Self: ~const Bar;
|
fn b() where Self: ~const Bar;
|
||||||
|
fn c<T: ~const Bar>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn test1<T: ~const Foo + Bar>() {
|
const fn test1<T: ~const Foo + Bar>() {
|
||||||
T::a();
|
T::a();
|
||||||
T::b();
|
T::b();
|
||||||
//~^ ERROR the trait bound
|
//~^ ERROR the trait bound
|
||||||
|
T::c::<T>();
|
||||||
|
//~^ ERROR the trait bound
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn test2<T: ~const Foo + ~const Bar>() {
|
const fn test2<T: ~const Foo + ~const Bar>() {
|
||||||
T::a();
|
T::a();
|
||||||
T::b();
|
T::b();
|
||||||
|
T::c::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test3<T: Foo>() {
|
fn test3<T: Foo>() {
|
||||||
T::a();
|
T::a();
|
||||||
T::b();
|
T::b();
|
||||||
//~^ ERROR the trait bound
|
//~^ ERROR the trait bound
|
||||||
|
T::c::<T>();
|
||||||
|
//~^ ERROR the trait bound
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test4<T: Foo + Bar>() {
|
fn test4<T: Foo + Bar>() {
|
||||||
T::a();
|
T::a();
|
||||||
T::b();
|
T::b();
|
||||||
|
T::c::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0277]: the trait bound `T: Bar` is not satisfied
|
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||||
--> $DIR/trait-where-clause.rs:13:5
|
--> $DIR/trait-where-clause.rs:14:5
|
||||||
|
|
|
|
||||||
LL | T::b();
|
LL | T::b();
|
||||||
| ^^^^ the trait `Bar` is not implemented for `T`
|
| ^^^^ the trait `Bar` is not implemented for `T`
|
||||||
|
@ -15,7 +15,23 @@ LL | const fn test1<T: ~const Foo + Bar + Bar>() {
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
error[E0277]: the trait bound `T: Bar` is not satisfied
|
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||||
--> $DIR/trait-where-clause.rs:24:5
|
--> $DIR/trait-where-clause.rs:16:5
|
||||||
|
|
|
||||||
|
LL | T::c::<T>();
|
||||||
|
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
|
||||||
|
|
|
||||||
|
note: required by `Foo::c`
|
||||||
|
--> $DIR/trait-where-clause.rs:9:5
|
||||||
|
|
|
||||||
|
LL | fn c<T: ~const Bar>();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: consider further restricting this bound
|
||||||
|
|
|
||||||
|
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||||
|
--> $DIR/trait-where-clause.rs:28:5
|
||||||
|
|
|
|
||||||
LL | T::b();
|
LL | T::b();
|
||||||
| ^^^^ the trait `Bar` is not implemented for `T`
|
| ^^^^ the trait `Bar` is not implemented for `T`
|
||||||
|
@ -30,6 +46,22 @@ help: consider further restricting this bound
|
||||||
LL | fn test3<T: Foo + Bar>() {
|
LL | fn test3<T: Foo + Bar>() {
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||||
|
--> $DIR/trait-where-clause.rs:30:5
|
||||||
|
|
|
||||||
|
LL | T::c::<T>();
|
||||||
|
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
|
||||||
|
|
|
||||||
|
note: required by `Foo::c`
|
||||||
|
--> $DIR/trait-where-clause.rs:9:5
|
||||||
|
|
|
||||||
|
LL | fn c<T: ~const Bar>();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: consider further restricting this bound
|
||||||
|
|
|
||||||
|
LL | fn test3<T: Foo + Bar>() {
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue