2020-10-09 10:45:29 +00:00
|
|
|
// compile-flags: --emit=link
|
2019-04-07 09:11:06 +00:00
|
|
|
// no-prefer-dynamic
|
2019-04-08 19:23:39 +00:00
|
|
|
// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
|
|
|
|
// crates. If we don't set this, compiletest will override the `crate_type` attribute below and
|
|
|
|
// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
|
|
|
|
// contain a proc-macro.
|
2019-04-07 09:11:06 +00:00
|
|
|
|
|
|
|
#![feature(repr128)]
|
2020-10-22 12:23:14 +00:00
|
|
|
#![allow(incomplete_features)]
|
2019-04-07 09:11:06 +00:00
|
|
|
#![crate_type = "proc-macro"]
|
|
|
|
|
|
|
|
extern crate proc_macro;
|
|
|
|
|
|
|
|
use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn macro_test(input_stream: TokenStream) -> TokenStream {
|
|
|
|
let first_token = input_stream.into_iter().next().unwrap();
|
|
|
|
let span = first_token.span();
|
|
|
|
|
|
|
|
TokenStream::from_iter(vec![
|
|
|
|
TokenTree::Ident(Ident::new("fn", Span::call_site())),
|
|
|
|
TokenTree::Ident(Ident::new("code", Span::call_site())),
|
|
|
|
TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
|
|
|
|
TokenTree::Group(Group::new(Delimiter::Brace, {
|
|
|
|
let mut clause = Group::new(Delimiter::Brace, TokenStream::new());
|
|
|
|
clause.set_span(span);
|
|
|
|
|
|
|
|
TokenStream::from_iter(vec![
|
|
|
|
TokenTree::Ident(Ident::new("if", Span::call_site())),
|
|
|
|
TokenTree::Ident(Ident::new("true", Span::call_site())),
|
|
|
|
TokenTree::Group(clause.clone()),
|
|
|
|
TokenTree::Ident(Ident::new("else", Span::call_site())),
|
2019-09-16 15:50:36 +00:00
|
|
|
TokenTree::Group(clause),
|
2019-04-07 09:11:06 +00:00
|
|
|
])
|
|
|
|
})),
|
|
|
|
])
|
|
|
|
}
|