Skip to content

Commit aca0bac

Browse files
author
Keegan McAllister
committed
Convert libraries to use #[plugin_registrar]
1 parent ed41b71 commit aca0bac

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

src/doc/rust.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,8 @@ type int8_t = i8;
18191819

18201820
### Function-only attributes
18211821

1822-
- `macro_registrar` - when using loadable syntax extensions, mark this
1823-
function as the registration point for the current crate's syntax
1824-
extensions.
1822+
- `plugin_registrar` - mark this function as the registration point for
1823+
compiler plugins, such as loadable syntax extensions.
18251824
- `main` - indicates that this function should be passed to the entry point,
18261825
rather than the function in the crate root named `main`.
18271826
- `start` - indicates that this function should be used as the entry point,

src/libfourcc/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,25 @@ fn main() {
4848
html_root_url = "http://doc.rust-lang.org/")]
4949

5050
#![deny(deprecated_owned_vector)]
51-
#![feature(macro_registrar, managed_boxes)]
51+
#![feature(plugin_registrar, managed_boxes)]
5252

5353
extern crate syntax;
54+
extern crate rustc;
5455

5556
use syntax::ast;
56-
use syntax::ast::Name;
5757
use syntax::attr::contains;
5858
use syntax::codemap::{Span, mk_sp};
5959
use syntax::ext::base;
60-
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
60+
use syntax::ext::base::{ExtCtxt, MacExpr};
6161
use syntax::ext::build::AstBuilder;
6262
use syntax::parse;
6363
use syntax::parse::token;
6464
use syntax::parse::token::InternedString;
65+
use rustc::plugin::Registry;
6566

66-
#[macro_registrar]
67-
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
68-
register(token::intern("fourcc"),
69-
NormalTT(box BasicMacroExpander {
70-
expander: expand_syntax_ext,
71-
span: None,
72-
},
73-
None));
67+
#[plugin_registrar]
68+
pub fn plugin_registrar(reg: &mut Registry) {
69+
reg.register_macro("fourcc", expand_syntax_ext);
7470
}
7571

7672
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])

src/libhexfloat/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,23 @@ fn main() {
4545
html_root_url = "http://doc.rust-lang.org/")]
4646

4747
#![deny(deprecated_owned_vector)]
48-
#![feature(macro_registrar, managed_boxes)]
48+
#![feature(plugin_registrar, managed_boxes)]
4949

5050
extern crate syntax;
51+
extern crate rustc;
5152

5253
use syntax::ast;
53-
use syntax::ast::Name;
5454
use syntax::codemap::{Span, mk_sp};
5555
use syntax::ext::base;
56-
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr};
56+
use syntax::ext::base::{ExtCtxt, MacExpr};
5757
use syntax::ext::build::AstBuilder;
5858
use syntax::parse;
5959
use syntax::parse::token;
60+
use rustc::plugin::Registry;
6061

61-
#[macro_registrar]
62-
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
63-
register(token::intern("hexfloat"),
64-
NormalTT(box BasicMacroExpander {
65-
expander: expand_syntax_ext,
66-
span: None,
67-
},
68-
None));
62+
#[plugin_registrar]
63+
pub fn plugin_registrar(reg: &mut Registry) {
64+
reg.register_macro("hexfloat", expand_syntax_ext);
6965
}
7066

7167
//Check if the literal is valid (as LLVM expects),

src/libregex_macros/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2020
html_root_url = "http://doc.rust-lang.org/")]
2121

22-
#![feature(macro_registrar, managed_boxes, quote)]
22+
#![feature(plugin_registrar, managed_boxes, quote)]
2323

2424
extern crate regex;
2525
extern crate syntax;
26+
extern crate rustc;
2627

2728
use std::rc::Rc;
2829

2930
use syntax::ast;
3031
use syntax::codemap;
3132
use syntax::ext::build::AstBuilder;
32-
use syntax::ext::base::{
33-
SyntaxExtension, ExtCtxt, MacResult, MacExpr, DummyResult,
34-
NormalTT, BasicMacroExpander,
35-
};
33+
use syntax::ext::base::{ExtCtxt, MacResult, MacExpr, DummyResult};
3634
use syntax::parse;
3735
use syntax::parse::token;
3836
use syntax::print::pprust;
3937

38+
use rustc::plugin::Registry;
39+
4040
use regex::Regex;
4141
use regex::native::{
4242
OneChar, CharClass, Any, Save, Jump, Split,
@@ -46,11 +46,10 @@ use regex::native::{
4646
};
4747

4848
/// For the `regex!` syntax extension. Do not use.
49-
#[macro_registrar]
49+
#[plugin_registrar]
5050
#[doc(hidden)]
51-
pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) {
52-
let expander = box BasicMacroExpander { expander: native, span: None };
53-
register(token::intern("regex"), NormalTT(expander, None))
51+
pub fn plugin_registrar(reg: &mut Registry) {
52+
reg.register_macro("regex", native);
5453
}
5554

5655
/// Generates specialized code for the Pike VM for a particular regular

0 commit comments

Comments
 (0)