]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/proc-macro/auxiliary/hygiene_example_codegen.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / proc-macro / auxiliary / hygiene_example_codegen.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 // no-prefer-dynamic
12
13 #![feature(proc_macro_quote, proc_macro_hygiene)]
14 #![crate_type = "proc-macro"]
15
16 extern crate proc_macro as proc_macro_renamed; // This does not break `quote!`
17
18 use proc_macro_renamed::{TokenStream, quote};
19
20 #[proc_macro]
21 pub fn hello(input: TokenStream) -> TokenStream {
22 quote!(hello_helper!($input))
23 //^ `hello_helper!` always resolves to the following proc macro,
24 //| no matter where `hello!` is used.
25 }
26
27 #[proc_macro]
28 pub fn hello_helper(input: TokenStream) -> TokenStream {
29 quote! {
30 extern crate hygiene_example; // This is never a conflict error
31 let string = format!("hello {}", $input);
32 //^ `format!` always resolves to the prelude macro,
33 //| even if a different `format!` is in scope where `hello!` is used.
34 hygiene_example::print(&string)
35 }
36 }