Skip to content

Commit 43c326e

Browse files
committed
Followup to PR #16477: a run-pass regression test for Issue #15750.
1 parent 385c39a commit 43c326e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/test/auxiliary/macro_crate_test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use syntax::ast::{TokenTree, Item, MetaItem};
1919
use syntax::codemap::Span;
2020
use syntax::ext::base::*;
2121
use syntax::parse::token;
22+
use syntax::parse;
2223
use rustc::plugin::Registry;
2324

2425
use std::gc::{Gc, GC};
@@ -32,6 +33,7 @@ macro_rules! unexported_macro (() => (3i))
3233
pub 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, 1i))
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+
4860
fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: Gc<MetaItem>, it: Gc<Item>)
4961
-> Gc<Item> {
5062
box(GC) Item {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:macro_crate_test.rs
12+
// ignore-stage1
13+
14+
// Issue #15750: a macro that internally parses its input and then
15+
// uses `quote_expr!` to rearrange it should be hygiene-preserving.
16+
17+
#![feature(phase)]
18+
19+
#[phase(plugin)]
20+
extern crate macro_crate_test;
21+
22+
fn main() {
23+
let x = 3i;
24+
assert_eq!(3, identity!(x));
25+
assert_eq!(6, identity!(x+x));
26+
let x = 4i;
27+
assert_eq!(4, identity!(x));
28+
}

0 commit comments

Comments
 (0)