Skip to content

Commit ee02c8e

Browse files
committed
Add test cases
1 parent 523490e commit ee02c8e

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// run-pass
2+
3+
#![feature(const_trait_impl)]
4+
#![feature(const_fn_trait_bound)]
5+
6+
trait Bar {
7+
fn bar() -> u8;
8+
}
9+
10+
trait Foo {
11+
#[default_method_body_is_const]
12+
fn foo() -> u8 where Self: ~const Bar {
13+
<Self as Bar>::bar() * 6
14+
}
15+
}
16+
17+
struct NonConst;
18+
struct Const;
19+
20+
impl Bar for NonConst {
21+
fn bar() -> u8 {
22+
3
23+
}
24+
}
25+
26+
impl Foo for NonConst {}
27+
28+
impl const Bar for Const {
29+
fn bar() -> u8 {
30+
4
31+
}
32+
}
33+
34+
impl const Foo for Const {}
35+
36+
fn main() {
37+
const ANS1: u8 = Const::foo();
38+
let ans2 = NonConst::foo();
39+
40+
assert_eq!(ANS1 + ans2, 42);
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
#![feature(const_trait_impl)]
4+
#![feature(const_fn_trait_bound)]
5+
6+
trait Foo {
7+
fn bar() where Self: ~const Foo;
8+
}
9+
10+
struct S;
11+
12+
impl Foo for S {
13+
fn bar() {}
14+
}
15+
16+
fn baz<T: Foo>() {
17+
T::bar();
18+
}
19+
20+
const fn qux<T: ~const Foo>() {
21+
T::bar();
22+
}
23+
24+
fn main() {}

Diff for: src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs

+7
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@ trait Bar {}
66
trait Foo {
77
fn a();
88
fn b() where Self: ~const Bar;
9+
fn c<T: ~const Bar>();
910
}
1011

1112
const fn test1<T: ~const Foo + Bar>() {
1213
T::a();
1314
T::b();
1415
//~^ ERROR the trait bound
16+
T::c::<T>();
17+
//~^ ERROR the trait bound
1518
}
1619

1720
const fn test2<T: ~const Foo + ~const Bar>() {
1821
T::a();
1922
T::b();
23+
T::c::<T>();
2024
}
2125

2226
fn test3<T: Foo>() {
2327
T::a();
2428
T::b();
2529
//~^ ERROR the trait bound
30+
T::c::<T>();
31+
//~^ ERROR the trait bound
2632
}
2733

2834
fn test4<T: Foo + Bar>() {
2935
T::a();
3036
T::b();
37+
T::c::<T>();
3138
}
3239

3340
fn main() {}

Diff for: src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `T: Bar` is not satisfied
2-
--> $DIR/trait-where-clause.rs:13:5
2+
--> $DIR/trait-where-clause.rs:14:5
33
|
44
LL | T::b();
55
| ^^^^ the trait `Bar` is not implemented for `T`
@@ -15,7 +15,23 @@ LL | const fn test1<T: ~const Foo + Bar + Bar>() {
1515
| +++++
1616

1717
error[E0277]: the trait bound `T: Bar` is not satisfied
18-
--> $DIR/trait-where-clause.rs:24:5
18+
--> $DIR/trait-where-clause.rs:16:5
19+
|
20+
LL | T::c::<T>();
21+
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
22+
|
23+
note: required by `Foo::c`
24+
--> $DIR/trait-where-clause.rs:9:5
25+
|
26+
LL | fn c<T: ~const Bar>();
27+
| ^^^^^^^^^^^^^^^^^^^^^^
28+
help: consider further restricting this bound
29+
|
30+
LL | const fn test1<T: ~const Foo + Bar + Bar>() {
31+
| +++++
32+
33+
error[E0277]: the trait bound `T: Bar` is not satisfied
34+
--> $DIR/trait-where-clause.rs:28:5
1935
|
2036
LL | T::b();
2137
| ^^^^ the trait `Bar` is not implemented for `T`
@@ -30,6 +46,22 @@ help: consider further restricting this bound
3046
LL | fn test3<T: Foo + Bar>() {
3147
| +++++
3248

33-
error: aborting due to 2 previous errors
49+
error[E0277]: the trait bound `T: Bar` is not satisfied
50+
--> $DIR/trait-where-clause.rs:30:5
51+
|
52+
LL | T::c::<T>();
53+
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
54+
|
55+
note: required by `Foo::c`
56+
--> $DIR/trait-where-clause.rs:9:5
57+
|
58+
LL | fn c<T: ~const Bar>();
59+
| ^^^^^^^^^^^^^^^^^^^^^^
60+
help: consider further restricting this bound
61+
|
62+
LL | fn test3<T: Foo + Bar>() {
63+
| +++++
64+
65+
error: aborting due to 4 previous errors
3466

3567
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)