File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
compiler/rustc_builtin_macros/src Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 11use rustc_ast as ast;
22use rustc_ast:: ptr:: P ;
3- use rustc_ast:: token;
4- use rustc_ast:: tokenstream:: TokenStream ;
3+ use rustc_ast:: token:: { self , Delimiter } ;
4+ use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
55use rustc_ast_pretty:: pprust;
66use rustc_expand:: base:: { self , * } ;
77use rustc_expand:: module:: DirOwnership ;
@@ -69,8 +69,17 @@ pub fn expand_file(
6969pub fn expand_stringify (
7070 cx : & mut ExtCtxt < ' _ > ,
7171 sp : Span ,
72- tts : TokenStream ,
72+ mut tts : TokenStream ,
7373) -> Box < dyn base:: MacResult + ' static > {
74+ // `stringify!` is nearly always called on `macro_rules` meta-variables and the intent is to
75+ // stringify the underlying tokens without meta-variable's own invisible delimiters, so we
76+ // are stripping such delimiters here (possibly multiple layers of them).
77+ while let [ TokenTree :: Delimited ( _, Delimiter :: Invisible , inner_tts) ] =
78+ & mut tts. clone ( ) . into_trees ( ) . collect :: < Vec < _ > > ( ) [ ..]
79+ {
80+ tts = inner_tts. clone ( ) ;
81+ }
82+
7483 let sp = cx. with_def_site_ctxt ( sp) ;
7584 let s = pprust:: tts_to_string ( & tts) ;
7685 base:: MacEager :: expr ( cx. expr_str ( sp, Symbol :: intern ( & s) ) )
You can’t perform that action at this time.
0 commit comments