]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_macros/src/lib.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / compiler / rustc_macros / src / lib.rs
CommitLineData
1b1a35ee 1#![feature(proc_macro_diagnostic)]
5e7ed085 2#![feature(allow_internal_unstable)]
e1599b0c 3#![allow(rustc::default_hash_types)]
dfeec247 4#![recursion_limit = "128"]
dc9dc135 5
532ac7d7
XL
6use synstructure::decl_derive;
7
8use proc_macro::TokenStream;
9
10mod hash_stable;
60c5eb7d 11mod lift;
5e7ed085 12mod newtype;
532ac7d7 13mod query;
3dfed10e 14mod serialize;
1b1a35ee 15mod session_diagnostic;
48663c56 16mod symbols;
dfeec247 17mod type_foldable;
532ac7d7
XL
18
19#[proc_macro]
20pub fn rustc_queries(input: TokenStream) -> TokenStream {
21 query::rustc_queries(input)
22}
23
48663c56
XL
24#[proc_macro]
25pub fn symbols(input: TokenStream) -> TokenStream {
fc512014 26 symbols::symbols(input.into()).into()
5e7ed085
FG
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)]
46pub fn newtype_index(input: TokenStream) -> TokenStream {
47 newtype::newtype(input).into()
48663c56
XL
48}
49
532ac7d7 50decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
60c5eb7d
XL
51decl_derive!(
52 [HashStable_Generic, attributes(stable_hasher)] =>
53 hash_stable::hash_stable_generic_derive
54);
55
3dfed10e
XL
56decl_derive!([Decodable] => serialize::decodable_derive);
57decl_derive!([Encodable] => serialize::encodable_derive);
58decl_derive!([TyDecodable] => serialize::type_decodable_derive);
59decl_derive!([TyEncodable] => serialize::type_encodable_derive);
60decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
61decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
60c5eb7d
XL
62decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
63decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
1b1a35ee
XL
64decl_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);