Skip to content

Commit

Permalink
Test for const expression missing braces
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Apr 28, 2020
1 parent e83f756 commit 2d57b1a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/ui/const-generics/const-expression-missing-braces.rs
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 src/test/ui/const-generics/const-expression-missing-braces.stderr
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`.

0 comments on commit 2d57b1a

Please sign in to comment.