Add tests

This commit is contained in:
Deadbeef 2022-01-29 01:49:15 +11:00
parent 08cb878430
commit 05bb26fdb6
5 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
const fn foo<T: Bar>(x: &T) {
x.a();
//~^ ERROR the trait bound
//~| ERROR cannot call
}
fn main() {}

View File

@ -0,0 +1,24 @@
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^ the trait `~const Foo` is not implemented for `T`
|
note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0015, E0277.
For more information about an error, try `rustc --explain E0015`.

View File

@ -0,0 +1,16 @@
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
struct S;
impl Foo for S {
fn a(&self) {}
}
impl const Bar for S {}
//~^ ERROR the trait bound
fn main() {}

View File

@ -0,0 +1,24 @@
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
--> $DIR/super-traits-fail.rs:13:12
|
LL | impl const Bar for S {}
| ^^^ the trait `~const Foo` is not implemented for `S`
|
note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
--> $DIR/super-traits-fail.rs:13:12
|
LL | impl const Bar for S {}
| ^^^
note: required by a bound in `Bar`
--> $DIR/super-traits-fail.rs:6:12
|
LL | trait Bar: ~const Foo {}
| ^^^^^^^^^^ required by this bound in `Bar`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | impl const Bar for S where S: ~const Foo {}
| +++++++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,22 @@
// check-pass
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
struct S;
impl const Foo for S {
fn a(&self) {}
}
impl const Bar for S {}
const fn foo<T: ~const Bar>(t: &T) {
t.a();
}
const _: () = foo(&S);
fn main() {}