Convert tests to use #[plugin_registrar]

This commit is contained in:
Keegan McAllister 2014-05-24 21:38:16 -07:00
parent aca0bac29f
commit 5084de3aaf
6 changed files with 30 additions and 36 deletions

View File

@ -10,29 +10,28 @@
// force-host // force-host
#![feature(globs, macro_registrar, macro_rules, quote, managed_boxes)] #![feature(globs, plugin_registrar, macro_rules, quote, managed_boxes)]
extern crate syntax; extern crate syntax;
extern crate rustc;
use syntax::ast::{Name, TokenTree, Item, MetaItem}; use syntax::ast::{TokenTree, Item, MetaItem};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::parse::token; use syntax::parse::token;
use rustc::plugin::Registry;
#[macro_export] #[macro_export]
macro_rules! exported_macro (() => (2)) macro_rules! exported_macro (() => (2))
macro_rules! unexported_macro (() => (3)) macro_rules! unexported_macro (() => (3))
#[macro_registrar] #[plugin_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) { pub fn plugin_registrar(reg: &mut Registry) {
register(token::intern("make_a_1"), reg.register_macro("make_a_1", expand_make_a_1);
NormalTT(box BasicMacroExpander { reg.register_syntax_extension(
expander: expand_make_a_1, token::intern("into_foo"),
span: None, ItemModifier(expand_into_foo));
},
None));
register(token::intern("into_foo"), ItemModifier(expand_into_foo));
} }
fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])

View File

@ -10,13 +10,12 @@
// force-host // force-host
#![feature(macro_registrar)] #![feature(plugin_registrar)]
extern crate syntax; extern crate rustc;
use std::any::Any; use std::any::Any;
use syntax::ast::Name; use rustc::plugin::Registry;
use syntax::ext::base::SyntaxExtension;
struct Foo { struct Foo {
foo: int foo: int
@ -26,8 +25,8 @@ impl Drop for Foo {
fn drop(&mut self) {} fn drop(&mut self) {}
} }
#[macro_registrar] #[plugin_registrar]
pub fn registrar(_: |Name, SyntaxExtension|) { pub fn registrar(_: &mut Registry) {
local_data_key!(foo: Box<Any:Send>); local_data_key!(foo: Box<Any:Send>);
foo.replace(Some(box Foo { foo: 10 } as Box<Any:Send>)); foo.replace(Some(box Foo { foo: 10 } as Box<Any:Send>));
} }

View File

@ -12,24 +12,20 @@
// no-prefer-dynamic // no-prefer-dynamic
#![crate_type = "dylib"] #![crate_type = "dylib"]
#![feature(macro_registrar, quote, globs)] #![feature(plugin_registrar, quote, globs)]
extern crate other = "syntax-extension-with-dll-deps-1"; extern crate other = "syntax-extension-with-dll-deps-1";
extern crate syntax; extern crate syntax;
extern crate rustc;
use syntax::ast::{Name, TokenTree, Item, MetaItem}; use syntax::ast::{TokenTree, Item, MetaItem};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::parse::token; use rustc::plugin::Registry;
#[macro_registrar] #[plugin_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) { pub fn plugin_registrar(reg: &mut Registry) {
register(token::intern("foo"), reg.register_macro("foo", expand_foo);
NormalTT(box BasicMacroExpander {
expander: expand_foo,
span: None,
},
None));
} }
fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
// the registration function isn't typechecked yet // the registration function isn't typechecked yet
#[macro_registrar] #[plugin_registrar]
pub fn registrar() {} //~ ERROR cross-crate macro exports are experimental pub fn registrar() {} //~ ERROR compiler plugins are experimental
fn main() {} fn main() {}

View File

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// error-pattern: multiple macro registration functions found // error-pattern: multiple plugin registration functions found
#![feature(macro_registrar)] #![feature(plugin_registrar)]
// the registration function isn't typechecked yet // the registration function isn't typechecked yet
#[macro_registrar] #[plugin_registrar]
pub fn one() {} pub fn one() {}
#[macro_registrar] #[plugin_registrar]
pub fn two() {} pub fn two() {}
fn main() {} fn main() {}

View File

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// aux-build:macro_crate_outlive_expansion_phase.rs // aux-build:plugin_crate_outlive_expansion_phase.rs
// ignore-stage1 // ignore-stage1
#![feature(phase)] #![feature(phase)]
#[phase(plugin)] #[phase(plugin)]
extern crate macro_crate_outlive_expansion_phase; extern crate plugin_crate_outlive_expansion_phase;
pub fn main() {} pub fn main() {}