Add tests
This commit is contained in:
parent
08cb878430
commit
05bb26fdb6
14
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
Normal file
14
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
Normal 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() {}
|
@ -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`.
|
16
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
Normal file
16
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
Normal 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() {}
|
@ -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`.
|
22
src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
Normal file
22
src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user