Followup to PR #16477: a run-pass regression test for Issue #15750.

This commit is contained in:
Felix S. Klock II 2014-08-14 11:55:47 +02:00
parent 385c39a77b
commit 43c326ef6b
2 changed files with 40 additions and 0 deletions

View File

@ -19,6 +19,7 @@
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::parse::token; use syntax::parse::token;
use syntax::parse;
use rustc::plugin::Registry; use rustc::plugin::Registry;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
@ -32,6 +33,7 @@ macro_rules! unexported_macro (() => (3i))
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("make_a_1", expand_make_a_1); reg.register_macro("make_a_1", expand_make_a_1);
reg.register_macro("forged_ident", expand_forged_ident); reg.register_macro("forged_ident", expand_forged_ident);
reg.register_macro("identity", expand_identity);
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("into_foo"), token::intern("into_foo"),
ItemModifier(expand_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)) 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>) fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: Gc<MetaItem>, it: Gc<Item>)
-> Gc<Item> { -> Gc<Item> {
box(GC) Item { box(GC) Item {

View 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));
}