forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
root testsuite: added huon's test case from rust-lang#15962.
But I think the one from rust-lang#15750 will be fine.
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | ||
} |