parent
385c39a77b
commit
43c326ef6b
@ -19,6 +19,7 @@
|
||||
use syntax::codemap::Span;
|
||||
use syntax::ext::base::*;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse;
|
||||
use rustc::plugin::Registry;
|
||||
|
||||
use std::gc::{Gc, GC};
|
||||
@ -32,6 +33,7 @@ macro_rules! unexported_macro (() => (3i))
|
||||
pub fn plugin_registrar(reg: &mut Registry) {
|
||||
reg.register_macro("make_a_1", expand_make_a_1);
|
||||
reg.register_macro("forged_ident", expand_forged_ident);
|
||||
reg.register_macro("identity", expand_identity);
|
||||
reg.register_syntax_extension(
|
||||
token::intern("into_foo"),
|
||||
ItemModifier(expand_into_foo));
|
||||
@ -45,6 +47,16 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
|
||||
MacExpr::new(quote_expr!(cx, 1i))
|
||||
}
|
||||
|
||||
// See Issue #15750
|
||||
fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
|
||||
-> Box<MacResult> {
|
||||
// Parse an expression and emit it unchanged.
|
||||
let mut parser = parse::new_parser_from_tts(cx.parse_sess(),
|
||||
cx.cfg(), Vec::from_slice(tts));
|
||||
let expr = parser.parse_expr();
|
||||
MacExpr::new(quote_expr!(&mut *cx, $expr))
|
||||
}
|
||||
|
||||
fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: Gc<MetaItem>, it: Gc<Item>)
|
||||
-> Gc<Item> {
|
||||
box(GC) Item {
|
||||
|
28
src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs
Normal file
28
src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:macro_crate_test.rs
|
||||
// ignore-stage1
|
||||
|
||||
// Issue #15750: a macro that internally parses its input and then
|
||||
// uses `quote_expr!` to rearrange it should be hygiene-preserving.
|
||||
|
||||
#![feature(phase)]
|
||||
|
||||
#[phase(plugin)]
|
||||
extern crate macro_crate_test;
|
||||
|
||||
fn main() {
|
||||
let x = 3i;
|
||||
assert_eq!(3, identity!(x));
|
||||
assert_eq!(6, identity!(x+x));
|
||||
let x = 4i;
|
||||
assert_eq!(4, identity!(x));
|
||||
}
|
Loading…
Reference in New Issue
Block a user