rust/tests/ui/crashes/auxiliary/proc_macro_crash.rs

31 lines
1.1 KiB
Rust
Raw Normal View History

2019-04-07 04:11:06 -05:00
#![feature(repr128)]
2020-10-22 07:23:14 -05:00
#![allow(incomplete_features)]
2019-04-07 04:11:06 -05:00
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 10:50:36 -05:00
TokenTree::Group(clause),
2019-04-07 04:11:06 -05:00
])
})),
])
}