From 05bb26fdb6635508aaa75c26e593672a86d03084 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 29 Jan 2022 01:49:15 +1100 Subject: [PATCH] Add tests --- .../super-traits-fail-2.rs | 14 +++++++++++ .../super-traits-fail-2.stderr | 24 +++++++++++++++++++ .../super-traits-fail.rs | 16 +++++++++++++ .../super-traits-fail.stderr | 24 +++++++++++++++++++ .../rfc-2632-const-trait-impl/super-traits.rs | 22 +++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/super-traits.rs diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs new file mode 100644 index 00000000000..7b38c15afc2 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs @@ -0,0 +1,14 @@ +#![feature(const_trait_impl)] + +trait Foo { + fn a(&self); +} +trait Bar: ~const Foo {} + +const fn foo(x: &T) { + x.a(); + //~^ ERROR the trait bound + //~| ERROR cannot call +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr new file mode 100644 index 00000000000..1766cdbee8a --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr @@ -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 `::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`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs new file mode 100644 index 00000000000..af465cad3d2 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs @@ -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() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr new file mode 100644 index 00000000000..9e8b8f8c6ba --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr @@ -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`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs new file mode 100644 index 00000000000..aded4ca9a99 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs @@ -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: &T) { + t.a(); +} + +const _: () = foo(&S); + +fn main() {}