File tree 1 file changed +12
-3
lines changed
compiler/rustc_builtin_macros/src
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
use rustc_ast as ast;
2
2
use 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 } ;
5
5
use rustc_ast_pretty:: pprust;
6
6
use rustc_expand:: base:: { self , * } ;
7
7
use rustc_expand:: module:: DirOwnership ;
@@ -69,8 +69,17 @@ pub fn expand_file(
69
69
pub fn expand_stringify (
70
70
cx : & mut ExtCtxt < ' _ > ,
71
71
sp : Span ,
72
- tts : TokenStream ,
72
+ mut tts : TokenStream ,
73
73
) -> 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
+
74
83
let sp = cx. with_def_site_ctxt ( sp) ;
75
84
let s = pprust:: tts_to_string ( & tts) ;
76
85
base:: MacEager :: expr ( cx. expr_str ( sp, Symbol :: intern ( & s) ) )
You can’t perform that action at this time.
0 commit comments