Skip to content

Commit

Permalink
Followup to PR rust-lang#16477: a run-pass regression test for Issue r…
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Aug 14, 2014
1 parent 385c39a commit 43c326e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/auxiliary/macro_crate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use syntax::ast::{TokenTree, Item, MetaItem};
use syntax::codemap::Span;
use syntax::ext::base::*;
use syntax::parse::token;
use syntax::parse;
use rustc::plugin::Registry;

use std::gc::{Gc, GC};
Expand All @@ -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));
Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs
Original file line number Diff line number Diff line change
@@ -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));
}

2 comments on commit 43c326e

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors: retry

Please sign in to comment.