Skip to content

Commit 857dd8b

Browse files
committed
Add macro test for min-const-generics
1 parent 25f6938 commit 857dd8b

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#![feature(min_const_generics)]
2+
3+
struct Example<const N: usize>;
4+
5+
macro_rules! external_macro {
6+
() => {{
7+
//~^ ERROR expected type
8+
const X: usize = 1337;
9+
X
10+
}}
11+
}
12+
13+
trait Marker<const N: usize> {}
14+
impl<const N: usize> Marker<N> for Example<N> {}
15+
16+
fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
17+
//~^ ERROR wrong number of const
18+
//~| ERROR wrong number of type
19+
Example::<gimme_a_const!(marker)>
20+
//~^ ERROR wrong number of const
21+
//~| ERROR wrong number of type
22+
}
23+
24+
fn from_marker(_: impl Marker<{
25+
#[macro_export]
26+
macro_rules! inline { () => {{ 3 }} }; inline!()
27+
}>) {}
28+
29+
fn main() {
30+
let _ok = Example::<{
31+
#[macro_export]
32+
macro_rules! gimme_a_const {
33+
($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
34+
//~^ ERROR expected type
35+
//~| ERROR expected type
36+
};
37+
gimme_a_const!(run)
38+
}>;
39+
40+
let _fail = Example::<external_macro!()>;
41+
//~^ ERROR wrong number of const
42+
//~| ERROR wrong number of type
43+
44+
let _fail = Example::<gimme_a_const!()>;
45+
//~^ ERROR wrong number of const
46+
//~| ERROR wrong number of type
47+
//~| ERROR unexpected end of macro invocation
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
error: expected type, found `{`
2+
--> $DIR/macro-fail.rs:33:27
3+
|
4+
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
5+
| ----------------------
6+
| |
7+
| this macro call doesn't expand to a type
8+
| in this macro invocation
9+
...
10+
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type
12+
|
13+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
error: expected type, found `{`
16+
--> $DIR/macro-fail.rs:33:27
17+
|
18+
LL | Example::<gimme_a_const!(marker)>
19+
| ----------------------
20+
| |
21+
| this macro call doesn't expand to a type
22+
| in this macro invocation
23+
...
24+
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type
26+
|
27+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
28+
29+
error: expected type, found `{`
30+
--> $DIR/macro-fail.rs:6:10
31+
|
32+
LL | () => {{
33+
| __________^
34+
LL | |
35+
LL | | const X: usize = 1337;
36+
LL | | X
37+
LL | | }}
38+
| |___^ expected type
39+
...
40+
LL | let _fail = Example::<external_macro!()>;
41+
| -----------------
42+
| |
43+
| this macro call doesn't expand to a type
44+
| in this macro invocation
45+
|
46+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
47+
48+
error: unexpected end of macro invocation
49+
--> $DIR/macro-fail.rs:44:25
50+
|
51+
LL | macro_rules! gimme_a_const {
52+
| -------------------------- when calling this macro
53+
...
54+
LL | let _fail = Example::<gimme_a_const!()>;
55+
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
56+
57+
error[E0107]: wrong number of const arguments: expected 1, found 0
58+
--> $DIR/macro-fail.rs:16:26
59+
|
60+
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument
62+
63+
error[E0107]: wrong number of type arguments: expected 0, found 1
64+
--> $DIR/macro-fail.rs:16:33
65+
|
66+
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> {
67+
| ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument
68+
69+
error[E0107]: wrong number of const arguments: expected 1, found 0
70+
--> $DIR/macro-fail.rs:19:3
71+
|
72+
LL | Example::<gimme_a_const!(marker)>
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument
74+
75+
error[E0107]: wrong number of type arguments: expected 0, found 1
76+
--> $DIR/macro-fail.rs:19:13
77+
|
78+
LL | Example::<gimme_a_const!(marker)>
79+
| ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument
80+
81+
error[E0107]: wrong number of const arguments: expected 1, found 0
82+
--> $DIR/macro-fail.rs:40:15
83+
|
84+
LL | let _fail = Example::<external_macro!()>;
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument
86+
87+
error[E0107]: wrong number of type arguments: expected 0, found 1
88+
--> $DIR/macro-fail.rs:40:25
89+
|
90+
LL | let _fail = Example::<external_macro!()>;
91+
| ^^^^^^^^^^^^^^^^^ unexpected type argument
92+
93+
error[E0107]: wrong number of const arguments: expected 1, found 0
94+
--> $DIR/macro-fail.rs:44:15
95+
|
96+
LL | let _fail = Example::<gimme_a_const!()>;
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument
98+
99+
error[E0107]: wrong number of type arguments: expected 0, found 1
100+
--> $DIR/macro-fail.rs:44:25
101+
|
102+
LL | let _fail = Example::<gimme_a_const!()>;
103+
| ^^^^^^^^^^^^^^^^ unexpected type argument
104+
105+
error: aborting due to 12 previous errors
106+
107+
For more information about this error, try `rustc --explain E0107`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// run-pass
2+
#![feature(min_const_generics)]
3+
4+
struct Example<const N: usize>;
5+
6+
macro_rules! external_macro {
7+
() => {{
8+
const X: usize = 1337;
9+
X
10+
}}
11+
}
12+
13+
trait Marker<const N: usize> {}
14+
impl<const N: usize> Marker<N> for Example<N> {}
15+
16+
fn make_marker() -> impl Marker<{
17+
#[macro_export]
18+
macro_rules! const_macro { () => {{ 3 }} }; inline!()
19+
}> {
20+
Example::<{ const_macro!() }>
21+
}
22+
23+
fn from_marker(_: impl Marker<{
24+
#[macro_export]
25+
macro_rules! inline { () => {{ 3 }} }; inline!()
26+
}>) {}
27+
28+
fn main() {
29+
let _ok = Example::<{
30+
#[macro_export]
31+
macro_rules! gimme_a_const {
32+
($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
33+
};
34+
gimme_a_const!(run)
35+
}>;
36+
37+
let _ok = Example::<{ external_macro!() }>;
38+
39+
let _ok: [_; gimme_a_const!(blah)] = [0,0,0];
40+
let _ok: [[u8; gimme_a_const!(blah)]; gimme_a_const!(blah)];
41+
let _ok: [u8; gimme_a_const!(blah)];
42+
43+
let _ok: [u8; {
44+
#[macro_export]
45+
macro_rules! const_two { () => {{ 2 }} };
46+
const_two!()
47+
}];
48+
49+
let _ok = [0; {
50+
#[macro_export]
51+
macro_rules! const_three { () => {{ 3 }} };
52+
const_three!()
53+
}];
54+
let _ok = [0; const_three!()];
55+
56+
from_marker(make_marker());
57+
}

0 commit comments

Comments
 (0)