Skip to content

Commit 2a0c63b

Browse files
authored
Unrolled build for rust-lang#126928
Rollup merge of rust-lang#126928 - nnethercote:124141-pre, r=oli-obk Some `Nonterminal` removal precursors Small things to prepare for rust-lang#124141, more or less. r? ```@oli-obk```
2 parents 536235f + 2e4d547 commit 2a0c63b

File tree

5 files changed

+134
-3
lines changed

5 files changed

+134
-3
lines changed

compiler/rustc_ast/src/attr/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ impl MetaItem {
327327
I: Iterator<Item = &'a TokenTree>,
328328
{
329329
// FIXME: Share code with `parse_path`.
330-
let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() {
330+
let tt = tokens.next().map(|tt| TokenTree::uninterpolate(tt));
331+
let path = match tt.as_deref() {
331332
Some(&TokenTree::Token(
332333
Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span },
333334
_,
@@ -368,6 +369,12 @@ impl MetaItem {
368369
token::Nonterminal::NtPath(path) => (**path).clone(),
369370
_ => return None,
370371
},
372+
Some(TokenTree::Token(
373+
Token { kind: token::OpenDelim(_) | token::CloseDelim(_), .. },
374+
_,
375+
)) => {
376+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tt);
377+
}
371378
_ => return None,
372379
};
373380
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl AttrTokenStream {
224224
// Inner attributes are only supported on extern blocks, functions,
225225
// impls, and modules. All of these have their inner attributes
226226
// placed at the beginning of the rightmost outermost braced group:
227-
// e.g. fn foo() { #![my_attr} }
227+
// e.g. fn foo() { #![my_attr] }
228228
//
229229
// Therefore, we can insert them back into the right location
230230
// without needing to do any extra position tracking.

compiler/rustc_expand/src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ impl<'a> StripUnconfigured<'a> {
214214
) => {
215215
panic!("Nonterminal should have been flattened: {:?}", tree);
216216
}
217+
AttrTokenTree::Token(
218+
Token { kind: TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_), .. },
219+
_,
220+
) => {
221+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tree);
222+
}
217223
AttrTokenTree::Token(token, spacing) => {
218224
Some(AttrTokenTree::Token(token, spacing)).into_iter()
219225
}

tests/ui/macros/nonterminal-matching.rs

+30
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,34 @@ simple_nonterminal!(a, 'a, (x, y, z)); // OK
2323

2424
complex_nonterminal!(enum E {});
2525

26+
// `ident`, `lifetime`, and `tt` all work. Other fragments do not. See
27+
// https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment
28+
macro_rules! foo {
29+
(ident $x:ident) => { bar!(ident $x); };
30+
(lifetime $x:lifetime) => { bar!(lifetime $x); };
31+
(tt $x:tt) => { bar!(tt $x); };
32+
(expr $x:expr) => { bar!(expr $x); }; //~ ERROR: no rules expected the token `3`
33+
(literal $x:literal) => { bar!(literal $x); }; //~ ERROR: no rules expected the token `4`
34+
(path $x:path) => { bar!(path $x); }; //~ ERROR: no rules expected the token `a::b::c`
35+
(stmt $x:stmt) => { bar!(stmt $x); }; //~ ERROR: no rules expected the token `let abc = 0`
36+
}
37+
38+
macro_rules! bar {
39+
(ident abc) => {};
40+
(lifetime 'abc) => {};
41+
(tt 2) => {};
42+
(expr 3) => {};
43+
(literal 4) => {};
44+
(path a::b::c) => {};
45+
(stmt let abc = 0) => {};
46+
}
47+
48+
foo!(ident abc);
49+
foo!(lifetime 'abc);
50+
foo!(tt 2);
51+
foo!(expr 3);
52+
foo!(literal 4);
53+
foo!(path a::b::c);
54+
foo!(stmt let abc = 0);
55+
2656
fn main() {}

tests/ui/macros/nonterminal-matching.stderr

+89-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,93 @@ LL | complex_nonterminal!(enum E {});
2323
= help: try using `:tt` instead in the macro definition
2424
= note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

26-
error: aborting due to 1 previous error
26+
error: no rules expected the token `3`
27+
--> $DIR/nonterminal-matching.rs:32:35
28+
|
29+
LL | (expr $x:expr) => { bar!(expr $x); };
30+
| ^^ no rules expected this token in macro call
31+
...
32+
LL | macro_rules! bar {
33+
| ---------------- when calling this macro
34+
...
35+
LL | foo!(expr 3);
36+
| ------------ in this macro invocation
37+
|
38+
note: while trying to match `3`
39+
--> $DIR/nonterminal-matching.rs:42:11
40+
|
41+
LL | (expr 3) => {};
42+
| ^
43+
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
44+
= note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
45+
= help: try using `:tt` instead in the macro definition
46+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
47+
48+
error: no rules expected the token `4`
49+
--> $DIR/nonterminal-matching.rs:33:44
50+
|
51+
LL | (literal $x:literal) => { bar!(literal $x); };
52+
| ^^ no rules expected this token in macro call
53+
...
54+
LL | macro_rules! bar {
55+
| ---------------- when calling this macro
56+
...
57+
LL | foo!(literal 4);
58+
| --------------- in this macro invocation
59+
|
60+
note: while trying to match `4`
61+
--> $DIR/nonterminal-matching.rs:43:14
62+
|
63+
LL | (literal 4) => {};
64+
| ^
65+
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
66+
= note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
67+
= help: try using `:tt` instead in the macro definition
68+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
69+
70+
error: no rules expected the token `a::b::c`
71+
--> $DIR/nonterminal-matching.rs:34:35
72+
|
73+
LL | (path $x:path) => { bar!(path $x); };
74+
| ^^ no rules expected this token in macro call
75+
...
76+
LL | macro_rules! bar {
77+
| ---------------- when calling this macro
78+
...
79+
LL | foo!(path a::b::c);
80+
| ------------------ in this macro invocation
81+
|
82+
note: while trying to match `a`
83+
--> $DIR/nonterminal-matching.rs:44:11
84+
|
85+
LL | (path a::b::c) => {};
86+
| ^
87+
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
88+
= note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
89+
= help: try using `:tt` instead in the macro definition
90+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
91+
92+
error: no rules expected the token `let abc = 0`
93+
--> $DIR/nonterminal-matching.rs:35:35
94+
|
95+
LL | (stmt $x:stmt) => { bar!(stmt $x); };
96+
| ^^ no rules expected this token in macro call
97+
...
98+
LL | macro_rules! bar {
99+
| ---------------- when calling this macro
100+
...
101+
LL | foo!(stmt let abc = 0);
102+
| ---------------------- in this macro invocation
103+
|
104+
note: while trying to match `let`
105+
--> $DIR/nonterminal-matching.rs:45:11
106+
|
107+
LL | (stmt let abc = 0) => {};
108+
| ^^^
109+
= note: captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens
110+
= note: see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information
111+
= help: try using `:tt` instead in the macro definition
112+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
113+
114+
error: aborting due to 5 previous errors
27115

0 commit comments

Comments
 (0)