]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_macros/src/lib.rs
Rollup merge of #93400 - ChayimFriedman2:dont-suggest-using-const-with-bounds-unused...
[rust.git] / compiler / rustc_macros / src / lib.rs
1 #![feature(proc_macro_diagnostic)]
2 #![feature(allow_internal_unstable)]
3 #![allow(rustc::default_hash_types)]
4 #![recursion_limit = "128"]
5
6 use synstructure::decl_derive;
7
8 use proc_macro::TokenStream;
9
10 mod hash_stable;
11 mod lift;
12 mod newtype;
13 mod query;
14 mod serialize;
15 mod session_diagnostic;
16 mod symbols;
17 mod type_foldable;
18
19 #[proc_macro]
20 pub fn rustc_queries(input: TokenStream) -> TokenStream {
21     query::rustc_queries(input)
22 }
23
24 #[proc_macro]
25 pub fn symbols(input: TokenStream) -> TokenStream {
26     symbols::symbols(input.into()).into()
27 }
28
29 /// Creates a struct type `S` that can be used as an index with
30 /// `IndexVec` and so on.
31 ///
32 /// There are two ways of interacting with these indices:
33 ///
34 /// - The `From` impls are the preferred way. So you can do
35 ///   `S::from(v)` with a `usize` or `u32`. And you can convert back
36 ///   to an integer with `u32::from(s)`.
37 ///
38 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
39 ///   to create/return a value.
40 ///
41 /// Internally, the index uses a u32, so the index must not exceed
42 /// `u32::MAX`. You can also customize things like the `Debug` impl,
43 /// what traits are derived, and so forth via the macro.
44 #[proc_macro]
45 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step)]
46 pub fn newtype_index(input: TokenStream) -> TokenStream {
47     newtype::newtype(input).into()
48 }
49
50 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
51 decl_derive!(
52     [HashStable_Generic, attributes(stable_hasher)] =>
53     hash_stable::hash_stable_generic_derive
54 );
55
56 decl_derive!([Decodable] => serialize::decodable_derive);
57 decl_derive!([Encodable] => serialize::encodable_derive);
58 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
59 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
60 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
61 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
62 decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
63 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
64 decl_derive!(
65     [SessionDiagnostic, attributes(
66         message,
67         lint,
68         error,
69         label,
70         suggestion,
71         suggestion_short,
72         suggestion_hidden,
73         suggestion_verbose)] => session_diagnostic::session_diagnostic_derive
74 );