]> git.lizzy.rs Git - rust.git/blob - src/test/auxiliary/macro_crate_test.rs
auto merge of #13967 : richo/rust/features/ICE-fails, r=alexcrichton
[rust.git] / src / test / auxiliary / macro_crate_test.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // force-host
12
13 #![feature(globs, macro_registrar, macro_rules, quote, managed_boxes)]
14
15 extern crate syntax;
16
17 use syntax::ast::{Name, TokenTree, Item, MetaItem};
18 use syntax::codemap::Span;
19 use syntax::ext::base::*;
20 use syntax::parse::token;
21
22 #[macro_export]
23 macro_rules! exported_macro (() => (2))
24
25 macro_rules! unexported_macro (() => (3))
26
27 #[macro_registrar]
28 pub fn macro_registrar(register: |Name, SyntaxExtension|) {
29     register(token::intern("make_a_1"),
30         NormalTT(box BasicMacroExpander {
31             expander: expand_make_a_1,
32             span: None,
33         },
34         None));
35     register(token::intern("into_foo"), ItemModifier(expand_into_foo));
36 }
37
38 fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
39                    -> Box<MacResult> {
40     if !tts.is_empty() {
41         cx.span_fatal(sp, "make_a_1 takes no arguments");
42     }
43     MacExpr::new(quote_expr!(cx, 1i))
44 }
45
46 fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: @MetaItem, it: @Item)
47                    -> @Item {
48     @Item {
49         attrs: it.attrs.clone(),
50         ..(*quote_item!(cx, enum Foo { Bar, Baz }).unwrap()).clone()
51     }
52 }
53
54 pub fn foo() {}