@@ -19,6 +19,7 @@ use syntax::ast::{TokenTree, Item, MetaItem};
1919use syntax:: codemap:: Span ;
2020use syntax:: ext:: base:: * ;
2121use syntax:: parse:: token;
22+ use syntax:: parse;
2223use rustc:: plugin:: Registry ;
2324
2425use std:: gc:: { Gc , GC } ;
@@ -32,6 +33,7 @@ macro_rules! unexported_macro (() => (3i))
3233pub fn plugin_registrar ( reg : & mut Registry ) {
3334 reg. register_macro ( "make_a_1" , expand_make_a_1) ;
3435 reg. register_macro ( "forged_ident" , expand_forged_ident) ;
36+ reg. register_macro ( "identity" , expand_identity) ;
3537 reg. register_syntax_extension (
3638 token:: intern ( "into_foo" ) ,
3739 ItemModifier ( expand_into_foo) ) ;
@@ -45,6 +47,16 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
4547 MacExpr :: new ( quote_expr ! ( cx, 1 i) )
4648}
4749
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+
4860fn expand_into_foo ( cx : & mut ExtCtxt , sp : Span , attr : Gc < MetaItem > , it : Gc < Item > )
4961 -> Gc < Item > {
5062 box ( GC ) Item {
0 commit comments