Skip to content

Remove NtExpr. #96724

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

Closed
Closed
Changes from 1 commit
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
Next Next commit
builtin_macros: Strip top-level invisible delimiters in stringify!.
  • Loading branch information
petrochenkov authored and nnethercote committed May 26, 2022
commit cda26a773a74f68bb9a1420cdfb012bec84b9abe
15 changes: 12 additions & 3 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::token::{self, Delimiter};
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirOwnership;
Expand Down Expand Up @@ -69,8 +69,17 @@ pub fn expand_file(
pub fn expand_stringify(
cx: &mut ExtCtxt<'_>,
sp: Span,
tts: TokenStream,
mut tts: TokenStream,
) -> Box<dyn base::MacResult + 'static> {
// `stringify!` is nearly always called on `macro_rules` meta-variables and the intent is to
// stringify the underlying tokens without meta-variable's own invisible delimiters, so we
// are stripping such delimiters here (possibly multiple layers of them).
while let [TokenTree::Delimited(_, Delimiter::Invisible, inner_tts)] =
&mut tts.clone().into_trees().collect::<Vec<_>>()[..]
{
tts = inner_tts.clone();
}

let sp = cx.with_def_site_ctxt(sp);
let s = pprust::tts_to_string(&tts);
base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s)))
Expand Down