1 #![feature(allow_internal_unstable)]
3 #![feature(never_type)]
4 #![feature(proc_macro_diagnostic)]
5 #![feature(proc_macro_span)]
6 #![allow(rustc::default_hash_types)]
7 #![recursion_limit = "128"]
9 use synstructure::decl_derive;
11 use proc_macro::TokenStream;
24 pub fn rustc_queries(input: TokenStream) -> TokenStream {
25 query::rustc_queries(input)
29 pub fn symbols(input: TokenStream) -> TokenStream {
30 symbols::symbols(input.into()).into()
33 /// Creates a struct type `S` that can be used as an index with
34 /// `IndexVec` and so on.
36 /// There are two ways of interacting with these indices:
38 /// - The `From` impls are the preferred way. So you can do
39 /// `S::from(v)` with a `usize` or `u32`. And you can convert back
40 /// to an integer with `u32::from(s)`.
42 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
43 /// to create/return a value.
45 /// Internally, the index uses a u32, so the index must not exceed
46 /// `u32::MAX`. You can also customize things like the `Debug` impl,
47 /// what traits are derived, and so forth via the macro.
49 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step)]
50 pub fn newtype_index(input: TokenStream) -> TokenStream {
51 newtype::newtype(input)
54 /// Implements the `fluent_messages` macro, which performs compile-time validation of the
55 /// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same
56 /// messages) and generates constants that make using those messages in diagnostics more ergonomic.
58 /// For example, given the following invocation of the macro..
61 /// fluent_messages! {
62 /// typeck => "./typeck.ftl",
65 /// ..where `typeck.ftl` has the following contents..
68 /// typeck-field-multiply-specified-in-initializer =
69 /// field `{$ident}` specified more than once
70 /// .label = used more than once
71 /// .label-previous-use = first use of `{$ident}`
73 /// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and
74 /// will generate the following code:
77 /// pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
78 /// include_str!("./typeck.ftl"),
81 /// mod fluent_generated {
83 /// pub const field_multiply_specified_in_initializer: DiagnosticMessage =
84 /// DiagnosticMessage::fluent("typeck-field-multiply-specified-in-initializer");
85 /// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
86 /// DiagnosticMessage::fluent_attr(
87 /// "typeck-field-multiply-specified-in-initializer",
88 /// "previous-use-label"
93 /// When emitting a diagnostic, the generated constants can be used as follows:
96 /// let mut err = sess.struct_span_err(
98 /// fluent::typeck::field_multiply_specified_in_initializer
100 /// err.span_default_label(span);
102 /// previous_use_span,
103 /// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
108 pub fn fluent_messages(input: TokenStream) -> TokenStream {
109 diagnostics::fluent_messages(input)
112 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
114 [HashStable_Generic, attributes(stable_hasher)] =>
115 hash_stable::hash_stable_generic_derive
118 decl_derive!([Decodable] => serialize::decodable_derive);
119 decl_derive!([Encodable] => serialize::encodable_derive);
120 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
121 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
122 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
123 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
124 decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
125 decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive);
126 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
128 [SessionDiagnostic, attributes(
142 suggestion_verbose)] => diagnostics::session_diagnostic_derive
145 [SessionSubdiagnostic, attributes(
146 // struct/variant attributes
157 applicability)] => diagnostics::session_subdiagnostic_derive