Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand: Stop normalizing NtIdents before passing them to built-in macros #77275

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn parse_reg<'a>(
explicit_reg: &mut bool,
) -> Result<ast::InlineAsmRegOrRegClass, DiagnosticBuilder<'a>> {
p.expect(&token::OpenDelim(token::DelimToken::Paren))?;
let result = match p.token.kind {
let result = match p.token.uninterpolate().kind {
token::Ident(name, false) => ast::InlineAsmRegOrRegClass::RegClass(name),
token::Literal(token::Lit { kind: token::LitKind::Str, symbol, suffix: _ }) => {
*explicit_reg = true;
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_builtin_macros/src/concat_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ pub fn expand_concat_idents<'cx>(
}
}
} else {
match e {
TokenTree::Token(Token { kind: token::Ident(name, _), .. }) => {
res_str.push_str(&name.as_str())
}
_ => {
cx.span_err(sp, "concat_idents! requires ident args.");
return DummyResult::any(sp);
if let TokenTree::Token(token) = e {
if let Some((ident, _)) = token.ident() {
res_str.push_str(&ident.name.as_str());
continue;
}
}

cx.span_err(sp, "concat_idents! requires ident args.");
return DummyResult::any(sp);
}
}

Expand Down
33 changes: 5 additions & 28 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::expand::{self, AstFragment, Invocation};
use crate::module::DirectoryOwnership;

use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::{self, TokenStream};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_ast::{self as ast, Attribute, NodeId, PatKind};
use rustc_attr::{self as attr, Deprecation, HasAttrs, Stability};
Expand Down Expand Up @@ -313,7 +312,7 @@ where
ts: TokenStream,
) -> Result<TokenStream, ErrorReported> {
// FIXME setup implicit context in TLS before calling self.
Ok((*self)(ts))
Ok(self(ts))
}
}

Expand All @@ -339,7 +338,7 @@ where
annotated: TokenStream,
) -> Result<TokenStream, ErrorReported> {
// FIXME setup implicit context in TLS before calling self.
Ok((*self)(annotation, annotated))
Ok(self(annotation, annotated))
}
}

Expand All @@ -364,31 +363,9 @@ where
&self,
ecx: &'cx mut ExtCtxt<'_>,
span: Span,
mut input: TokenStream,
input: TokenStream,
) -> Box<dyn MacResult + 'cx> {
struct AvoidInterpolatedIdents;

impl MutVisitor for AvoidInterpolatedIdents {
fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) {
if let tokenstream::TokenTree::Token(token) = tt {
if let token::Interpolated(nt) = &token.kind {
if let token::NtIdent(ident, is_raw) = **nt {
*tt = tokenstream::TokenTree::token(
token::Ident(ident.name, is_raw),
ident.span,
);
}
}
}
mut_visit::noop_visit_tt(tt, self)
}

fn visit_mac(&mut self, mac: &mut ast::MacCall) {
mut_visit::noop_visit_mac(mac, self)
}
}
AvoidInterpolatedIdents.visit_tts(&mut input);
(*self)(ecx, span, input)
self(ecx, span, input)
}
}

Expand Down