Skip to content

Commit f369713

Browse files
committed
root testsuite: added huon's test case from rust-lang#15962.
But I think the one from rust-lang#15750 will be fine.
1 parent b6cf028 commit f369713

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FILES= test.bin
2+
# FILES= test_gensym.bin test.bin
23

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

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

2526
test.bin: plugin.dylib
2627

28+
test_gensym.bin: gensym.dylib
29+
2730
%.dot: %.rs Makefile objdir-dbg/x86_64-apple-darwin/stage2/rustc
2831
$(RUSTC) -Z flowgraph-print-all --pretty flowgraph=% $< -o $@
2932

gensym.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// gensym.rs
2+
3+
// Taken from Issue #15962
4+
5+
#![feature(plugin_registrar, managed_boxes, quote)]
6+
#![crate_type = "dylib"]
7+
8+
extern crate syntax;
9+
extern crate rustc;
10+
11+
use syntax::ast;
12+
use syntax::codemap::{Span};
13+
use syntax::ext::base;
14+
use syntax::ext::base::{ExtCtxt, MacExpr};
15+
use syntax::ext::build::AstBuilder;
16+
use syntax::parse::token;
17+
use rustc::plugin::Registry;
18+
19+
#[plugin_registrar]
20+
pub fn plugin_registrar(reg: &mut Registry) {
21+
reg.register_macro("test_quote", expand_syntax_ext);
22+
}
23+
24+
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, _: &[ast::TokenTree]) -> Box<base::MacResult> {
25+
// expand to `{ let foo = true; foo }`, with a gensym'd foo.
26+
let ident = token::gensym_ident("foo");
27+
let decl = quote_stmt!(&mut *cx, let $ident = true;);
28+
let result = cx.expr_block(cx.block(sp, vec![decl], Some(cx.expr_ident(sp, ident))));
29+
30+
println!("{}", result);
31+
32+
MacExpr::new(result)
33+
}
34+

test_gensym.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// test_gensym.rs
2+
3+
// Taken from Issue #15962
4+
5+
#![feature(phase)]
6+
7+
#[phase(plugin)] extern crate gensym;
8+
9+
fn main() {
10+
let a = test_quote!();
11+
}

0 commit comments

Comments
 (0)