Skip to content

Commit

Permalink
root testsuite: added huon's test case from rust-lang#15962.
Browse files Browse the repository at this point in the history
But I think the one from rust-lang#15750 will be fine.
  • Loading branch information
pnkfelix committed Aug 1, 2014
1 parent b6cf028 commit f369713
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FILES= test.bin
# FILES= test_gensym.bin test.bin

all: $(patsubst %.rs,%.dot,$(FILES))

Expand All @@ -24,6 +25,8 @@ RUST_LOG=rustc::middle::borrowck,rustc::middle::ty,rustc::middle::typeck,rustc::

test.bin: plugin.dylib

test_gensym.bin: gensym.dylib

%.dot: %.rs Makefile objdir-dbg/x86_64-apple-darwin/stage2/rustc
$(RUSTC) -Z flowgraph-print-all --pretty flowgraph=% $< -o $@

Expand Down
34 changes: 34 additions & 0 deletions gensym.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// gensym.rs

// Taken from Issue #15962

#![feature(plugin_registrar, managed_boxes, quote)]
#![crate_type = "dylib"]

extern crate syntax;
extern crate rustc;

use syntax::ast;
use syntax::codemap::{Span};
use syntax::ext::base;
use syntax::ext::base::{ExtCtxt, MacExpr};
use syntax::ext::build::AstBuilder;
use syntax::parse::token;
use rustc::plugin::Registry;

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("test_quote", expand_syntax_ext);
}

pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, _: &[ast::TokenTree]) -> Box<base::MacResult> {
// expand to `{ let foo = true; foo }`, with a gensym'd foo.
let ident = token::gensym_ident("foo");
let decl = quote_stmt!(&mut *cx, let $ident = true;);
let result = cx.expr_block(cx.block(sp, vec![decl], Some(cx.expr_ident(sp, ident))));

println!("{}", result);

MacExpr::new(result)
}

11 changes: 11 additions & 0 deletions test_gensym.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// test_gensym.rs

// Taken from Issue #15962

#![feature(phase)]

#[phase(plugin)] extern crate gensym;

fn main() {
let a = test_quote!();
}

0 comments on commit f369713

Please sign in to comment.