]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/auxiliary/hello_macro.rs
New upstream version 1.18.0+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / auxiliary / hello_macro.rs
1 // Copyright 2017 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 #![feature(plugin)]
12 #![feature(plugin_registrar)]
13 #![feature(rustc_private)]
14 #![plugin(proc_macro_plugin)]
15
16 extern crate rustc_plugin;
17 extern crate syntax;
18
19 use rustc_plugin::Registry;
20 use syntax::ext::base::SyntaxExtension;
21 use syntax::symbol::Symbol;
22 use syntax::tokenstream::TokenStream;
23
24 #[plugin_registrar]
25 pub fn plugin_registrar(reg: &mut Registry) {
26 reg.register_syntax_extension(Symbol::intern("hello"),
27 SyntaxExtension::ProcMacro(Box::new(hello)));
28 }
29
30 // This macro is not very interesting, but it does contain delimited tokens with
31 // no content - `()` and `{}` - which has caused problems in the past.
32 // Also, it tests that we can escape `$` via `$$`.
33 fn hello(_: TokenStream) -> TokenStream {
34 quote!({
35 fn hello() {}
36 macro_rules! m { ($$($$t:tt)*) => { $$($$t)* } }
37 m!(hello());
38 })
39 }