Skip to content

Commit dd78188

Browse files
committed
add macro_rules test regarding braces
1 parent 359031e commit dd78188

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error: expressions must be enclosed in braces to be used as const generic arguments
2+
--> $DIR/macro_rules-braces.rs:34:17
3+
|
4+
LL | let _: baz!(N);
5+
| ^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ N });
10+
| ^ ^
11+
12+
error: constant expression depends on a generic parameter
13+
--> $DIR/macro_rules-braces.rs:10:13
14+
|
15+
LL | [u8; $x]
16+
| ^^^^^^^^
17+
...
18+
LL | let _: foo!({{ N }});
19+
| ------------- in this macro invocation
20+
|
21+
= note: this may fail depending on what value the parameter takes
22+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: constant expression depends on a generic parameter
25+
--> $DIR/macro_rules-braces.rs:15:13
26+
|
27+
LL | [u8; { $x }]
28+
| ^^^^^^^^^^^^
29+
...
30+
LL | let _: bar!({ N });
31+
| ----------- in this macro invocation
32+
|
33+
= note: this may fail depending on what value the parameter takes
34+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
35+
36+
error: constant expression depends on a generic parameter
37+
--> $DIR/macro_rules-braces.rs:20:13
38+
|
39+
LL | Foo<$x>
40+
| ^^^^^^^
41+
...
42+
LL | let _: baz!({{ N }});
43+
| ------------- in this macro invocation
44+
|
45+
= note: this may fail depending on what value the parameter takes
46+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
47+
48+
error: constant expression depends on a generic parameter
49+
--> $DIR/macro_rules-braces.rs:25:13
50+
|
51+
LL | Foo<{ $x }>
52+
| ^^^^^^^^^^^
53+
...
54+
LL | let _: biz!({ N });
55+
| ----------- in this macro invocation
56+
|
57+
= note: this may fail depending on what value the parameter takes
58+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
59+
60+
error: aborting due to 5 previous errors
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: expressions must be enclosed in braces to be used as const generic arguments
2+
--> $DIR/macro_rules-braces.rs:34:17
3+
|
4+
LL | let _: baz!(N);
5+
| ^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ N });
10+
| ^ ^
11+
12+
error: generic parameters may not be used in const operations
13+
--> $DIR/macro_rules-braces.rs:31:20
14+
|
15+
LL | let _: foo!({{ N }});
16+
| ^ cannot perform const operation using `N`
17+
|
18+
= help: const parameters may only be used as standalone arguments, i.e. `N`
19+
20+
error: generic parameters may not be used in const operations
21+
--> $DIR/macro_rules-braces.rs:33:19
22+
|
23+
LL | let _: bar!({ N });
24+
| ^ cannot perform const operation using `N`
25+
|
26+
= help: const parameters may only be used as standalone arguments, i.e. `N`
27+
28+
error: generic parameters may not be used in const operations
29+
--> $DIR/macro_rules-braces.rs:36:20
30+
|
31+
LL | let _: baz!({{ N }});
32+
| ^ cannot perform const operation using `N`
33+
|
34+
= help: const parameters may only be used as standalone arguments, i.e. `N`
35+
36+
error: generic parameters may not be used in const operations
37+
--> $DIR/macro_rules-braces.rs:38:19
38+
|
39+
LL | let _: biz!({ N });
40+
| ^ cannot perform const operation using `N`
41+
|
42+
= help: const parameters may only be used as standalone arguments, i.e. `N`
43+
44+
error: aborting due to 5 previous errors
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// revisions: full min
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
fn test<const N: usize>() {
7+
struct Foo<const M: usize>;
8+
macro_rules! foo {
9+
($x:expr) => {
10+
[u8; $x] //[full]~ ERROR constant expression depends
11+
}
12+
}
13+
macro_rules! bar {
14+
($x:expr) => {
15+
[u8; { $x }] //[full]~ ERROR constant expression depends
16+
}
17+
}
18+
macro_rules! baz {
19+
( $x:expr) => {
20+
Foo<$x> //[full]~ ERROR constant expression depends
21+
}
22+
}
23+
macro_rules! biz {
24+
($x:expr) => {
25+
Foo<{ $x }> //[full]~ ERROR constant expression depends
26+
};
27+
}
28+
29+
let _: foo!(N);
30+
let _: foo!({ N });
31+
let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
32+
let _: bar!(N);
33+
let _: bar!({ N }); //[min]~ ERROR generic parameters may not
34+
let _: baz!(N); //~ ERROR expressions must be enclosed in braces
35+
let _: baz!({ N });
36+
let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
37+
let _: biz!(N);
38+
let _: biz!({ N }); //[min]~ ERROR generic parameters may not
39+
}
40+
41+
fn main() {
42+
test::<3>();
43+
}

0 commit comments

Comments
 (0)