Skip to content

Commit

Permalink
add macro_rules test regarding braces
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 10, 2020
1 parent 359031e commit dd78188
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/test/ui/const-generics/macro_rules-braces.full.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
error: expressions must be enclosed in braces to be used as const generic arguments
--> $DIR/macro_rules-braces.rs:34:17
|
LL | let _: baz!(N);
| ^
|
help: enclose the `const` expression in braces
|
LL | let _: baz!({ N });
| ^ ^

error: constant expression depends on a generic parameter
--> $DIR/macro_rules-braces.rs:10:13
|
LL | [u8; $x]
| ^^^^^^^^
...
LL | let _: foo!({{ N }});
| ------------- in this macro invocation
|
= note: this may fail depending on what value the parameter takes
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: constant expression depends on a generic parameter
--> $DIR/macro_rules-braces.rs:15:13
|
LL | [u8; { $x }]
| ^^^^^^^^^^^^
...
LL | let _: bar!({ N });
| ----------- in this macro invocation
|
= note: this may fail depending on what value the parameter takes
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: constant expression depends on a generic parameter
--> $DIR/macro_rules-braces.rs:20:13
|
LL | Foo<$x>
| ^^^^^^^
...
LL | let _: baz!({{ N }});
| ------------- in this macro invocation
|
= note: this may fail depending on what value the parameter takes
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: constant expression depends on a generic parameter
--> $DIR/macro_rules-braces.rs:25:13
|
LL | Foo<{ $x }>
| ^^^^^^^^^^^
...
LL | let _: biz!({ N });
| ----------- in this macro invocation
|
= note: this may fail depending on what value the parameter takes
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 5 previous errors

45 changes: 45 additions & 0 deletions src/test/ui/const-generics/macro_rules-braces.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
error: expressions must be enclosed in braces to be used as const generic arguments
--> $DIR/macro_rules-braces.rs:34:17
|
LL | let _: baz!(N);
| ^
|
help: enclose the `const` expression in braces
|
LL | let _: baz!({ N });
| ^ ^

error: generic parameters may not be used in const operations
--> $DIR/macro_rules-braces.rs:31:20
|
LL | let _: foo!({{ N }});
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`

error: generic parameters may not be used in const operations
--> $DIR/macro_rules-braces.rs:33:19
|
LL | let _: bar!({ N });
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`

error: generic parameters may not be used in const operations
--> $DIR/macro_rules-braces.rs:36:20
|
LL | let _: baz!({{ N }});
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`

error: generic parameters may not be used in const operations
--> $DIR/macro_rules-braces.rs:38:19
|
LL | let _: biz!({ N });
| ^ cannot perform const operation using `N`
|
= help: const parameters may only be used as standalone arguments, i.e. `N`

error: aborting due to 5 previous errors

43 changes: 43 additions & 0 deletions src/test/ui/const-generics/macro_rules-braces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// revisions: full min
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(min, feature(min_const_generics))]

fn test<const N: usize>() {
struct Foo<const M: usize>;
macro_rules! foo {
($x:expr) => {
[u8; $x] //[full]~ ERROR constant expression depends
}
}
macro_rules! bar {
($x:expr) => {
[u8; { $x }] //[full]~ ERROR constant expression depends
}
}
macro_rules! baz {
( $x:expr) => {
Foo<$x> //[full]~ ERROR constant expression depends
}
}
macro_rules! biz {
($x:expr) => {
Foo<{ $x }> //[full]~ ERROR constant expression depends
};
}

let _: foo!(N);
let _: foo!({ N });
let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
let _: bar!(N);
let _: bar!({ N }); //[min]~ ERROR generic parameters may not
let _: baz!(N); //~ ERROR expressions must be enclosed in braces
let _: baz!({ N });
let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
let _: biz!(N);
let _: biz!({ N }); //[min]~ ERROR generic parameters may not
}

fn main() {
test::<3>();
}

0 comments on commit dd78188

Please sign in to comment.