From ee02c8e20a5098e77251bb07cca5fe9b932c84d7 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sat, 28 Aug 2021 15:53:26 +0000 Subject: [PATCH] Add test cases --- .../trait-where-clause-run.rs | 41 +++++++++++++++++++ .../trait-where-clause-self-referential.rs | 24 +++++++++++ .../trait-where-clause.rs | 7 ++++ .../trait-where-clause.stderr | 38 +++++++++++++++-- 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs new file mode 100644 index 00000000000..0cde5b6f842 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs @@ -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 { + ::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); +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs new file mode 100644 index 00000000000..ae9ab26cdc0 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs @@ -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::bar(); +} + +const fn qux() { + T::bar(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs index 7fcd791e722..d64822d7ce8 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -6,28 +6,35 @@ trait Bar {} trait Foo { fn a(); fn b() where Self: ~const Bar; + fn c(); } const fn test1() { T::a(); T::b(); //~^ ERROR the trait bound + T::c::(); + //~^ ERROR the trait bound } const fn test2() { T::a(); T::b(); + T::c::(); } fn test3() { T::a(); T::b(); //~^ ERROR the trait bound + T::c::(); + //~^ ERROR the trait bound } fn test4() { T::a(); T::b(); + T::c::(); } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr index f70792ba55a..fffb91f9870 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -1,5 +1,5 @@ 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(); | ^^^^ the trait `Bar` is not implemented for `T` @@ -15,7 +15,23 @@ LL | const fn test1() { | +++++ 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::(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1() { + | +++++ + +error[E0277]: the trait bound `T: Bar` is not satisfied + --> $DIR/trait-where-clause.rs:28:5 | LL | T::b(); | ^^^^ the trait `Bar` is not implemented for `T` @@ -30,6 +46,22 @@ help: consider further restricting this bound LL | fn test3() { | +++++ -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::(); + | ^^^^^^^^^ the trait `Bar` is not implemented for `T` + | +note: required by `Foo::c` + --> $DIR/trait-where-clause.rs:9:5 + | +LL | fn c(); + | ^^^^^^^^^^^^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | fn test3() { + | +++++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`.