]> git.lizzy.rs Git - rust.git/blob - tests/ui/crashes/auxiliary/proc_macro_crash.rs
Use the traits added to the Rust 2021 Edition prelude
[rust.git] / tests / ui / crashes / auxiliary / proc_macro_crash.rs
1 // compile-flags: --emit=link
2 // no-prefer-dynamic
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.
7
8 #![feature(repr128)]
9 #![allow(incomplete_features)]
10 #![crate_type = "proc-macro"]
11
12 extern crate proc_macro;
13
14 use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
15
16 #[proc_macro]
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();
20
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);
28
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),
35             ])
36         })),
37     ])
38 }