]>
Commit | Line | Data |
---|---|---|
5e7ed085 | 1 | #![feature(allow_internal_unstable)] |
04454e1e FG |
2 | #![feature(let_else)] |
3 | #![feature(never_type)] | |
4 | #![feature(proc_macro_diagnostic)] | |
e1599b0c | 5 | #![allow(rustc::default_hash_types)] |
dfeec247 | 6 | #![recursion_limit = "128"] |
dc9dc135 | 7 | |
532ac7d7 XL |
8 | use synstructure::decl_derive; |
9 | ||
10 | use proc_macro::TokenStream; | |
11 | ||
04454e1e | 12 | mod diagnostics; |
532ac7d7 | 13 | mod hash_stable; |
60c5eb7d | 14 | mod lift; |
5e7ed085 | 15 | mod newtype; |
532ac7d7 | 16 | mod query; |
3dfed10e | 17 | mod serialize; |
48663c56 | 18 | mod symbols; |
dfeec247 | 19 | mod type_foldable; |
532ac7d7 XL |
20 | |
21 | #[proc_macro] | |
22 | pub fn rustc_queries(input: TokenStream) -> TokenStream { | |
23 | query::rustc_queries(input) | |
24 | } | |
25 | ||
48663c56 XL |
26 | #[proc_macro] |
27 | pub fn symbols(input: TokenStream) -> TokenStream { | |
fc512014 | 28 | symbols::symbols(input.into()).into() |
5e7ed085 FG |
29 | } |
30 | ||
31 | /// Creates a struct type `S` that can be used as an index with | |
32 | /// `IndexVec` and so on. | |
33 | /// | |
34 | /// There are two ways of interacting with these indices: | |
35 | /// | |
36 | /// - The `From` impls are the preferred way. So you can do | |
37 | /// `S::from(v)` with a `usize` or `u32`. And you can convert back | |
38 | /// to an integer with `u32::from(s)`. | |
39 | /// | |
40 | /// - Alternatively, you can use the methods `S::new(v)` and `s.index()` | |
41 | /// to create/return a value. | |
42 | /// | |
43 | /// Internally, the index uses a u32, so the index must not exceed | |
44 | /// `u32::MAX`. You can also customize things like the `Debug` impl, | |
45 | /// what traits are derived, and so forth via the macro. | |
46 | #[proc_macro] | |
47 | #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step)] | |
48 | pub fn newtype_index(input: TokenStream) -> TokenStream { | |
04454e1e | 49 | newtype::newtype(input) |
48663c56 XL |
50 | } |
51 | ||
532ac7d7 | 52 | decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); |
60c5eb7d XL |
53 | decl_derive!( |
54 | [HashStable_Generic, attributes(stable_hasher)] => | |
55 | hash_stable::hash_stable_generic_derive | |
56 | ); | |
57 | ||
3dfed10e XL |
58 | decl_derive!([Decodable] => serialize::decodable_derive); |
59 | decl_derive!([Encodable] => serialize::encodable_derive); | |
60 | decl_derive!([TyDecodable] => serialize::type_decodable_derive); | |
61 | decl_derive!([TyEncodable] => serialize::type_encodable_derive); | |
62 | decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive); | |
63 | decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive); | |
60c5eb7d XL |
64 | decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive); |
65 | decl_derive!([Lift, attributes(lift)] => lift::lift_derive); | |
1b1a35ee XL |
66 | decl_derive!( |
67 | [SessionDiagnostic, attributes( | |
04454e1e FG |
68 | // struct attributes |
69 | warning, | |
1b1a35ee | 70 | error, |
04454e1e FG |
71 | note, |
72 | help, | |
73 | // field attributes | |
74 | skip_arg, | |
75 | primary_span, | |
76 | label, | |
77 | subdiagnostic, | |
78 | suggestion, | |
79 | suggestion_short, | |
80 | suggestion_hidden, | |
81 | suggestion_verbose)] => diagnostics::session_diagnostic_derive | |
82 | ); | |
83 | decl_derive!( | |
84 | [SessionSubdiagnostic, attributes( | |
85 | // struct/variant attributes | |
1b1a35ee | 86 | label, |
04454e1e FG |
87 | help, |
88 | note, | |
1b1a35ee XL |
89 | suggestion, |
90 | suggestion_short, | |
91 | suggestion_hidden, | |
04454e1e FG |
92 | suggestion_verbose, |
93 | // field attributes | |
94 | skip_arg, | |
95 | primary_span, | |
96 | applicability)] => diagnostics::session_subdiagnostic_derive | |
1b1a35ee | 97 | ); |