@@ -19,6 +19,7 @@ use syntax::ast::{TokenTree, Item, MetaItem};
19
19
use syntax:: codemap:: Span ;
20
20
use syntax:: ext:: base:: * ;
21
21
use syntax:: parse:: token;
22
+ use syntax:: parse;
22
23
use rustc:: plugin:: Registry ;
23
24
24
25
use std:: gc:: { Gc , GC } ;
@@ -32,6 +33,7 @@ macro_rules! unexported_macro (() => (3i))
32
33
pub fn plugin_registrar ( reg : & mut Registry ) {
33
34
reg. register_macro ( "make_a_1" , expand_make_a_1) ;
34
35
reg. register_macro ( "forged_ident" , expand_forged_ident) ;
36
+ reg. register_macro ( "identity" , expand_identity) ;
35
37
reg. register_syntax_extension (
36
38
token:: intern ( "into_foo" ) ,
37
39
ItemModifier ( expand_into_foo) ) ;
@@ -45,6 +47,16 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
45
47
MacExpr :: new ( quote_expr ! ( cx, 1 i) )
46
48
}
47
49
50
+ // See Issue #15750
51
+ fn expand_identity ( cx : & mut ExtCtxt , _span : Span , tts : & [ TokenTree ] )
52
+ -> Box < MacResult > {
53
+ // Parse an expression and emit it unchanged.
54
+ let mut parser = parse:: new_parser_from_tts ( cx. parse_sess ( ) ,
55
+ cx. cfg ( ) , Vec :: from_slice ( tts) ) ;
56
+ let expr = parser. parse_expr ( ) ;
57
+ MacExpr :: new ( quote_expr ! ( & mut * cx, $expr) )
58
+ }
59
+
48
60
fn expand_into_foo ( cx : & mut ExtCtxt , sp : Span , attr : Gc < MetaItem > , it : Gc < Item > )
49
61
-> Gc < Item > {
50
62
box ( GC ) Item {
0 commit comments