Skip to content

Commit 2532a7e

Browse files
committed
expand: Stop un-interpolating NtIdents before passing them to built-in macros
This was a big hack, and built-in macros should be able to deal with `NtIdents` in the input by themselves like any other parser code.
1 parent d902752 commit 2532a7e

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

compiler/rustc_builtin_macros/src/concat_idents.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ pub fn expand_concat_idents<'cx>(
2727
}
2828
}
2929
} else {
30-
match e {
31-
TokenTree::Token(Token { kind: token::Ident(name, _), .. }) => {
32-
res_str.push_str(&name.as_str())
33-
}
34-
_ => {
35-
cx.span_err(sp, "concat_idents! requires ident args.");
36-
return DummyResult::any(sp);
30+
if let TokenTree::Token(token) = e {
31+
if let Some((ident, _)) = token.ident() {
32+
res_str.push_str(&ident.name.as_str());
33+
continue;
3734
}
3835
}
36+
37+
cx.span_err(sp, "concat_idents! requires ident args.");
38+
return DummyResult::any(sp);
3939
}
4040
}
4141

compiler/rustc_expand/src/base.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::expand::{self, AstFragment, Invocation};
22
use crate::module::DirectoryOwnership;
33

4-
use rustc_ast::mut_visit::{self, MutVisitor};
54
use rustc_ast::ptr::P;
65
use rustc_ast::token;
7-
use rustc_ast::tokenstream::{self, TokenStream};
6+
use rustc_ast::tokenstream::TokenStream;
87
use rustc_ast::visit::{AssocCtxt, Visitor};
98
use rustc_ast::{self as ast, Attribute, NodeId, PatKind};
109
use rustc_attr::{self as attr, Deprecation, HasAttrs, Stability};
@@ -364,30 +363,8 @@ where
364363
&self,
365364
ecx: &'cx mut ExtCtxt<'_>,
366365
span: Span,
367-
mut input: TokenStream,
366+
input: TokenStream,
368367
) -> Box<dyn MacResult + 'cx> {
369-
struct AvoidInterpolatedIdents;
370-
371-
impl MutVisitor for AvoidInterpolatedIdents {
372-
fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) {
373-
if let tokenstream::TokenTree::Token(token) = tt {
374-
if let token::Interpolated(nt) = &token.kind {
375-
if let token::NtIdent(ident, is_raw) = **nt {
376-
*tt = tokenstream::TokenTree::token(
377-
token::Ident(ident.name, is_raw),
378-
ident.span,
379-
);
380-
}
381-
}
382-
}
383-
mut_visit::noop_visit_tt(tt, self)
384-
}
385-
386-
fn visit_mac(&mut self, mac: &mut ast::MacCall) {
387-
mut_visit::noop_visit_mac(mac, self)
388-
}
389-
}
390-
AvoidInterpolatedIdents.visit_tts(&mut input);
391368
(*self)(ecx, span, input)
392369
}
393370
}

0 commit comments

Comments
 (0)