• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![feature(allow_internal_unstable)]
2 #![feature(if_let_guard)]
3 #![feature(let_chains)]
4 #![feature(never_type)]
5 #![feature(proc_macro_diagnostic)]
6 #![feature(proc_macro_span)]
7 #![allow(rustc::default_hash_types)]
8 #![deny(rustc::untranslatable_diagnostic)]
9 #![deny(rustc::diagnostic_outside_of_impl)]
10 #![recursion_limit = "128"]
11 
12 use synstructure::decl_derive;
13 
14 use proc_macro::TokenStream;
15 
16 mod diagnostics;
17 mod hash_stable;
18 mod lift;
19 mod newtype;
20 mod query;
21 mod serialize;
22 mod symbols;
23 mod type_foldable;
24 mod type_visitable;
25 
26 #[proc_macro]
rustc_queries(input: TokenStream) -> TokenStream27 pub fn rustc_queries(input: TokenStream) -> TokenStream {
28     query::rustc_queries(input)
29 }
30 
31 #[proc_macro]
symbols(input: TokenStream) -> TokenStream32 pub fn symbols(input: TokenStream) -> TokenStream {
33     symbols::symbols(input.into()).into()
34 }
35 
36 /// Creates a struct type `S` that can be used as an index with
37 /// `IndexVec` and so on.
38 ///
39 /// There are two ways of interacting with these indices:
40 ///
41 /// - The `From` impls are the preferred way. So you can do
42 ///   `S::from(v)` with a `usize` or `u32`. And you can convert back
43 ///   to an integer with `u32::from(s)`.
44 ///
45 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
46 ///   to create/return a value.
47 ///
48 /// Internally, the index uses a u32, so the index must not exceed
49 /// `u32::MAX`. You can also customize things like the `Debug` impl,
50 /// what traits are derived, and so forth via the macro.
51 #[proc_macro]
52 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)]
newtype_index(input: TokenStream) -> TokenStream53 pub fn newtype_index(input: TokenStream) -> TokenStream {
54     newtype::newtype(input)
55 }
56 
57 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
58 decl_derive!(
59     [HashStable_Generic, attributes(stable_hasher)] =>
60     hash_stable::hash_stable_generic_derive
61 );
62 
63 decl_derive!([Decodable] => serialize::decodable_derive);
64 decl_derive!([Encodable] => serialize::encodable_derive);
65 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
66 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
67 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
68 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
69 decl_derive!(
70     [TypeFoldable, attributes(type_foldable)] =>
71     /// Derives `TypeFoldable` for the annotated `struct` or `enum` (`union` is not supported).
72     ///
73     /// The fold will produce a value of the same struct or enum variant as the input, with
74     /// each field respectively folded using the `TypeFoldable` implementation for its type.
75     /// However, if a field of a struct or an enum variant is annotated with
76     /// `#[type_foldable(identity)]` then that field will retain its incumbent value (and its
77     /// type is not required to implement `TypeFoldable`).
78     type_foldable::type_foldable_derive
79 );
80 decl_derive!(
81     [TypeVisitable, attributes(type_visitable)] =>
82     /// Derives `TypeVisitable` for the annotated `struct` or `enum` (`union` is not supported).
83     ///
84     /// Each field of the struct or enum variant will be visited in definition order, using the
85     /// `TypeVisitable` implementation for its type. However, if a field of a struct or an enum
86     /// variant is annotated with `#[type_visitable(ignore)]` then that field will not be
87     /// visited (and its type is not required to implement `TypeVisitable`).
88     type_visitable::type_visitable_derive
89 );
90 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
91 decl_derive!(
92     [Diagnostic, attributes(
93         // struct attributes
94         diag,
95         help,
96         note,
97         warning,
98         // field attributes
99         skip_arg,
100         primary_span,
101         label,
102         subdiagnostic,
103         suggestion,
104         suggestion_short,
105         suggestion_hidden,
106         suggestion_verbose)] => diagnostics::session_diagnostic_derive
107 );
108 decl_derive!(
109     [LintDiagnostic, attributes(
110         // struct attributes
111         diag,
112         help,
113         note,
114         warning,
115         // field attributes
116         skip_arg,
117         primary_span,
118         label,
119         subdiagnostic,
120         suggestion,
121         suggestion_short,
122         suggestion_hidden,
123         suggestion_verbose)] => diagnostics::lint_diagnostic_derive
124 );
125 decl_derive!(
126     [Subdiagnostic, attributes(
127         // struct/variant attributes
128         label,
129         help,
130         note,
131         warning,
132         suggestion,
133         suggestion_short,
134         suggestion_hidden,
135         suggestion_verbose,
136         multipart_suggestion,
137         multipart_suggestion_short,
138         multipart_suggestion_hidden,
139         multipart_suggestion_verbose,
140         // field attributes
141         skip_arg,
142         primary_span,
143         suggestion_part,
144         applicability)] => diagnostics::session_subdiagnostic_derive
145 );
146