-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for const expression missing braces
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/test/ui/const-generics/const-expression-missing-braces.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(const_generics)] | ||
|
||
fn foo<const C: usize>() {} | ||
|
||
fn a() { | ||
let bar = 3; | ||
foo::<bar + 3>(); | ||
//~^ ERROR expected one of `!`, `(`, `,`, `>`, `?`, `for`, lifetime, or path, found `3` | ||
} | ||
fn b() { | ||
let bar = 3; | ||
foo::<bar + bar>(); | ||
//~^ ERROR expected trait, found local variable `bar` | ||
//~| ERROR expected trait, found local variable `bar` | ||
//~| ERROR wrong number of const arguments: expected 1, found 0 | ||
//~| ERROR wrong number of type arguments: expected 0, found 1 | ||
//~| WARNING trait objects without an explicit `dyn` are deprecated | ||
} | ||
fn c() { | ||
let bar = 3; | ||
foo::<3 + 3>(); | ||
//~^ ERROR expected one of `,` or `>`, found `+` | ||
} | ||
|
||
fn main() {} |
48 changes: 48 additions & 0 deletions
48
src/test/ui/const-generics/const-expression-missing-braces.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error: expected one of `!`, `(`, `,`, `>`, `?`, `for`, lifetime, or path, found `3` | ||
--> $DIR/const-expression-missing-braces.rs:8:17 | ||
| | ||
LL | foo::<bar + 3>(); | ||
| ^ expected one of 8 possible tokens | ||
|
||
error: expected one of `,` or `>`, found `+` | ||
--> $DIR/const-expression-missing-braces.rs:22:13 | ||
| | ||
LL | foo::<3 + 3>(); | ||
| ^ expected one of `,` or `>` | ||
|
||
error[E0404]: expected trait, found local variable `bar` | ||
--> $DIR/const-expression-missing-braces.rs:13:11 | ||
| | ||
LL | foo::<bar + bar>(); | ||
| ^^^ not a trait | ||
|
||
error[E0404]: expected trait, found local variable `bar` | ||
--> $DIR/const-expression-missing-braces.rs:13:17 | ||
| | ||
LL | foo::<bar + bar>(); | ||
| ^^^ not a trait | ||
|
||
warning: trait objects without an explicit `dyn` are deprecated | ||
--> $DIR/const-expression-missing-braces.rs:13:11 | ||
| | ||
LL | foo::<bar + bar>(); | ||
| ^^^^^^^^^ help: use `dyn`: `dyn bar + bar` | ||
| | ||
= note: `#[warn(bare_trait_objects)]` on by default | ||
|
||
error[E0107]: wrong number of const arguments: expected 1, found 0 | ||
--> $DIR/const-expression-missing-braces.rs:13:5 | ||
| | ||
LL | foo::<bar + bar>(); | ||
| ^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/const-expression-missing-braces.rs:13:11 | ||
| | ||
LL | foo::<bar + bar>(); | ||
| ^^^^^^^^^ unexpected type argument | ||
|
||
error: aborting due to 6 previous errors; 1 warning emitted | ||
|
||
Some errors have detailed explanations: E0107, E0404. | ||
For more information about an error, try `rustc --explain E0107`. |