1 // compile-flags: --emit=link
3 // ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
4 // crates. If we don't set this, compiletest will override the `crate_type` attribute below and
5 // compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
6 // contain a proc-macro.
9 #![allow(incomplete_features)]
10 #![crate_type = "proc-macro"]
12 extern crate proc_macro;
14 use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
17 pub fn macro_test(input_stream: TokenStream) -> TokenStream {
18 let first_token = input_stream.into_iter().next().unwrap();
19 let span = first_token.span();
21 TokenStream::from_iter(vec![
22 TokenTree::Ident(Ident::new("fn", Span::call_site())),
23 TokenTree::Ident(Ident::new("code", Span::call_site())),
24 TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
25 TokenTree::Group(Group::new(Delimiter::Brace, {
26 let mut clause = Group::new(Delimiter::Brace, TokenStream::new());
27 clause.set_span(span);
29 TokenStream::from_iter(vec![
30 TokenTree::Ident(Ident::new("if", Span::call_site())),
31 TokenTree::Ident(Ident::new("true", Span::call_site())),
32 TokenTree::Group(clause.clone()),
33 TokenTree::Ident(Ident::new("else", Span::call_site())),
34 TokenTree::Group(clause),