Skip to content

Commit 85bc953

Browse files
committed
Add tests for multi-segment paths in const generic arguments
1 parent efcbf1b commit 85bc953

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

src/test/ui/const-generics/macro_rules-braces.full.stderr

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
error: expressions must be enclosed in braces to be used as const generic arguments
2-
--> $DIR/macro_rules-braces.rs:54:17
2+
--> $DIR/macro_rules-braces.rs:49:17
3+
|
4+
LL | let _: baz!(m::P);
5+
| ^^^^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ m::P });
10+
| ^ ^
11+
12+
error: expressions must be enclosed in braces to be used as const generic arguments
13+
--> $DIR/macro_rules-braces.rs:69:17
314
|
415
LL | let _: baz!(10 + 7);
516
| ^^^^^^
@@ -10,7 +21,7 @@ LL | let _: baz!({ 10 + 7 });
1021
| ^ ^
1122

1223
error: constant expression depends on a generic parameter
13-
--> $DIR/macro_rules-braces.rs:10:13
24+
--> $DIR/macro_rules-braces.rs:16:13
1425
|
1526
LL | [u8; $x]
1627
| ^^^^^^^^
@@ -22,7 +33,7 @@ LL | let _: foo!({{ N }});
2233
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2334

2435
error: constant expression depends on a generic parameter
25-
--> $DIR/macro_rules-braces.rs:15:13
36+
--> $DIR/macro_rules-braces.rs:21:13
2637
|
2738
LL | [u8; { $x }]
2839
| ^^^^^^^^^^^^
@@ -34,7 +45,7 @@ LL | let _: bar!({ N });
3445
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3546

3647
error: constant expression depends on a generic parameter
37-
--> $DIR/macro_rules-braces.rs:20:13
48+
--> $DIR/macro_rules-braces.rs:26:13
3849
|
3950
LL | Foo<$x>
4051
| ^^^^^^^
@@ -46,7 +57,7 @@ LL | let _: baz!({{ N }});
4657
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
4758

4859
error: constant expression depends on a generic parameter
49-
--> $DIR/macro_rules-braces.rs:25:13
60+
--> $DIR/macro_rules-braces.rs:31:13
5061
|
5162
LL | Foo<{ $x }>
5263
| ^^^^^^^^^^^
@@ -57,5 +68,5 @@ LL | let _: biz!({ N });
5768
= note: this may fail depending on what value the parameter takes
5869
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5970

60-
error: aborting due to 5 previous errors
71+
error: aborting due to 6 previous errors
6172

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
error: expressions must be enclosed in braces to be used as const generic arguments
2-
--> $DIR/macro_rules-braces.rs:54:17
2+
--> $DIR/macro_rules-braces.rs:49:17
3+
|
4+
LL | let _: baz!(m::P);
5+
| ^^^^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ m::P });
10+
| ^ ^
11+
12+
error: expressions must be enclosed in braces to be used as const generic arguments
13+
--> $DIR/macro_rules-braces.rs:69:17
314
|
415
LL | let _: baz!(10 + 7);
516
| ^^^^^^
@@ -10,36 +21,36 @@ LL | let _: baz!({ 10 + 7 });
1021
| ^ ^
1122

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

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

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

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

44-
error: aborting due to 5 previous errors
55+
error: aborting due to 6 previous errors
4556

src/test/ui/const-generics/macro_rules-braces.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#![cfg_attr(full, feature(const_generics))]
44
#![cfg_attr(min, feature(min_const_generics))]
55

6+
mod m {
7+
pub const P: usize = 0;
8+
}
9+
10+
const Q: usize = 0;
11+
612
fn test<const N: usize>() {
713
struct Foo<const M: usize>;
814
macro_rules! foo {
@@ -29,13 +35,22 @@ fn test<const N: usize>() {
2935
let _: foo!(N);
3036
let _: foo!({ N });
3137
let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
38+
let _: foo!(Q);
39+
let _: foo!(m::P);
3240
let _: bar!(N);
3341
let _: bar!({ N }); //[min]~ ERROR generic parameters may not
42+
let _: bar!(Q);
43+
let _: bar!(m::P);
3444
let _: baz!(N);
3545
let _: baz!({ N });
3646
let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
47+
let _: baz!(Q);
48+
let _: baz!({ m::P });
49+
let _: baz!(m::P); //~ ERROR expressions must be enclosed in braces
3750
let _: biz!(N);
3851
let _: biz!({ N }); //[min]~ ERROR generic parameters may not
52+
let _: biz!(Q);
53+
let _: biz!(m::P);
3954
let _: foo!(3);
4055
let _: foo!({ 3 });
4156
let _: foo!({{ 3 }});

0 commit comments

Comments
 (0)