]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // compile-flags: --emit=link |
2 | // no-prefer-dynamic | |
3 | ||
4 | #![crate_type = "proc-macro"] | |
5 | #![feature(repr128, proc_macro_quote)] | |
6 | #![allow(incomplete_features)] | |
7 | #![allow(clippy::field_reassign_with_default)] | |
8 | #![allow(clippy::eq_op)] | |
9 | ||
10 | extern crate proc_macro; | |
11 | ||
12 | use proc_macro::{quote, TokenStream}; | |
13 | ||
14 | #[proc_macro_derive(DeriveSomething)] | |
15 | pub fn derive(_: TokenStream) -> TokenStream { | |
16 | // Shound not trigger `used_underscore_binding` | |
17 | let _inside_derive = 1; | |
18 | assert_eq!(_inside_derive, _inside_derive); | |
19 | ||
20 | let output = quote! { | |
21 | // Should not trigger `useless_attribute` | |
22 | #[allow(dead_code)] | |
23 | extern crate rustc_middle; | |
24 | }; | |
25 | output | |
26 | } | |
27 | ||
28 | #[proc_macro_derive(FieldReassignWithDefault)] | |
29 | pub fn derive_foo(_input: TokenStream) -> TokenStream { | |
30 | quote! { | |
31 | #[derive(Default)] | |
32 | struct A { | |
33 | pub i: i32, | |
34 | pub j: i64, | |
35 | } | |
36 | #[automatically_derived] | |
37 | fn lint() { | |
38 | let mut a: A = Default::default(); | |
39 | a.i = 42; | |
40 | a; | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | #[proc_macro_derive(StructAUseSelf)] | |
46 | pub fn derive_use_self(_input: TokenStream) -> proc_macro::TokenStream { | |
47 | quote! { | |
48 | struct A; | |
49 | impl A { | |
50 | fn new() -> A { | |
51 | A | |
52 | } | |
53 | } | |
54 | } | |
55 | } |