Skip to content

Commit 2d57b1a

Browse files
committed
Test for const expression missing braces
1 parent e83f756 commit 2d57b1a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![allow(incomplete_features)]
2+
#![feature(const_generics)]
3+
4+
fn foo<const C: usize>() {}
5+
6+
fn a() {
7+
let bar = 3;
8+
foo::<bar + 3>();
9+
//~^ ERROR expected one of `!`, `(`, `,`, `>`, `?`, `for`, lifetime, or path, found `3`
10+
}
11+
fn b() {
12+
let bar = 3;
13+
foo::<bar + bar>();
14+
//~^ ERROR expected trait, found local variable `bar`
15+
//~| ERROR expected trait, found local variable `bar`
16+
//~| ERROR wrong number of const arguments: expected 1, found 0
17+
//~| ERROR wrong number of type arguments: expected 0, found 1
18+
//~| WARNING trait objects without an explicit `dyn` are deprecated
19+
}
20+
fn c() {
21+
let bar = 3;
22+
foo::<3 + 3>();
23+
//~^ ERROR expected one of `,` or `>`, found `+`
24+
}
25+
26+
fn main() {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error: expected one of `!`, `(`, `,`, `>`, `?`, `for`, lifetime, or path, found `3`
2+
--> $DIR/const-expression-missing-braces.rs:8:17
3+
|
4+
LL | foo::<bar + 3>();
5+
| ^ expected one of 8 possible tokens
6+
7+
error: expected one of `,` or `>`, found `+`
8+
--> $DIR/const-expression-missing-braces.rs:22:13
9+
|
10+
LL | foo::<3 + 3>();
11+
| ^ expected one of `,` or `>`
12+
13+
error[E0404]: expected trait, found local variable `bar`
14+
--> $DIR/const-expression-missing-braces.rs:13:11
15+
|
16+
LL | foo::<bar + bar>();
17+
| ^^^ not a trait
18+
19+
error[E0404]: expected trait, found local variable `bar`
20+
--> $DIR/const-expression-missing-braces.rs:13:17
21+
|
22+
LL | foo::<bar + bar>();
23+
| ^^^ not a trait
24+
25+
warning: trait objects without an explicit `dyn` are deprecated
26+
--> $DIR/const-expression-missing-braces.rs:13:11
27+
|
28+
LL | foo::<bar + bar>();
29+
| ^^^^^^^^^ help: use `dyn`: `dyn bar + bar`
30+
|
31+
= note: `#[warn(bare_trait_objects)]` on by default
32+
33+
error[E0107]: wrong number of const arguments: expected 1, found 0
34+
--> $DIR/const-expression-missing-braces.rs:13:5
35+
|
36+
LL | foo::<bar + bar>();
37+
| ^^^^^^^^^^^^^^^^ expected 1 const argument
38+
39+
error[E0107]: wrong number of type arguments: expected 0, found 1
40+
--> $DIR/const-expression-missing-braces.rs:13:11
41+
|
42+
LL | foo::<bar + bar>();
43+
| ^^^^^^^^^ unexpected type argument
44+
45+
error: aborting due to 6 previous errors; 1 warning emitted
46+
47+
Some errors have detailed explanations: E0107, E0404.
48+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)