Skip to content

Commit 3efd7ec

Browse files
committed
mbe: Extend metavariable expression tests
Add tests showing the current state to make it more clear when output gets updated later in refactoring.
1 parent b2c6e5a commit 3efd7ec

File tree

6 files changed

+242
-64
lines changed

6 files changed

+242
-64
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Our diagnostics should be able to point to a specific input that caused an invalid
2+
// identifier.
3+
4+
#![feature(macro_metavar_expr_concat)]
5+
6+
// See what we can do without expanding anything
7+
macro_rules! pre_expansion {
8+
($a:ident) => {
9+
${concat("hi", " bye ")};
10+
${concat("hi", "-", "bye")};
11+
${concat($a, "-")};
12+
}
13+
}
14+
15+
macro_rules! post_expansion {
16+
($a:literal) => {
17+
const _: () = ${concat("hi", $a, "bye")};
18+
//~^ ERROR is not generating a valid identifier
19+
}
20+
}
21+
22+
post_expansion!("!");
23+
24+
macro_rules! post_expansion_many {
25+
($a:ident, $b:ident, $c:ident, $d:literal, $e:ident) => {
26+
const _: () = ${concat($a, $b, $c, $d, $e)};
27+
//~^ ERROR is not generating a valid identifier
28+
}
29+
}
30+
31+
post_expansion_many!(a, b, c, ".d", e);
32+
33+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: `${concat(..)}` is not generating a valid identifier
2+
--> $DIR/concat-trace-errors.rs:17:24
3+
|
4+
LL | const _: () = ${concat("hi", $a, "bye")};
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | post_expansion!("!");
8+
| -------------------- in this macro invocation
9+
|
10+
= note: this error originates in the macro `post_expansion` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: `${concat(..)}` is not generating a valid identifier
13+
--> $DIR/concat-trace-errors.rs:26:24
14+
|
15+
LL | const _: () = ${concat($a, $b, $c, $d, $e)};
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
...
18+
LL | post_expansion_many!(a, b, c, ".d", e);
19+
| -------------------------------------- in this macro invocation
20+
|
21+
= note: this error originates in the macro `post_expansion_many` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error: aborting due to 2 previous errors
24+

tests/ui/macros/metavar-expressions/concat-usage-errors.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
//@ edition: 2021
2+
13
#![feature(macro_metavar_expr_concat)]
24

3-
macro_rules! wrong_concat_declarations {
5+
macro_rules! syntax_errors {
46
($ex:expr) => {
57
${concat()}
68
//~^ ERROR expected identifier
@@ -90,11 +92,31 @@ macro_rules! unsupported_literals {
9092
//~| ERROR expected pattern
9193
let ${concat(_a, 1)}: () = ();
9294
//~^ ERROR expected identifier or string literal
95+
let ${concat(_a, 1.5)}: () = ();
96+
//~^ ERROR expected identifier or string literal
97+
let ${concat(_a, c"hi")}: () = ();
98+
//~^ ERROR expected identifier or string literal
99+
let ${concat(_a, b"hi")}: () = ();
100+
//~^ ERROR expected identifier or string literal
101+
let ${concat(_a, b'b')}: () = ();
102+
//~^ ERROR expected identifier or string literal
103+
let ${concat(_a, b'b')}: () = ();
104+
//~^ ERROR expected identifier or string literal
93105

94106
let ${concat($ident, 'b')}: () = ();
95107
//~^ ERROR expected identifier or string literal
96108
let ${concat($ident, 1)}: () = ();
97109
//~^ ERROR expected identifier or string literal
110+
let ${concat($ident, 1.5)}: () = ();
111+
//~^ ERROR expected identifier or string literal
112+
let ${concat($ident, c"hi")}: () = ();
113+
//~^ ERROR expected identifier or string literal
114+
let ${concat($ident, b"hi")}: () = ();
115+
//~^ ERROR expected identifier or string literal
116+
let ${concat($ident, b'b')}: () = ();
117+
//~^ ERROR expected identifier or string literal
118+
let ${concat($ident, b'b')}: () = ();
119+
//~^ ERROR expected identifier or string literal
98120
}};
99121
}
100122

0 commit comments

Comments
 (0)