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;
23 pub fn rustc_queries(input: TokenStream) -> TokenStream {
24 query::rustc_queries(input)
28 pub fn symbols(input: TokenStream) -> TokenStream {
29 symbols::symbols(input.into()).into()
32 /// Creates a struct type `S` that can be used as an index with
33 /// `IndexVec` and so on.
35 /// There are two ways of interacting with these indices:
37 /// - The `From` impls are the preferred way. So you can do
38 /// `S::from(v)` with a `usize` or `u32`. And you can convert back
39 /// to an integer with `u32::from(s)`.
41 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
42 /// to create/return a value.
44 /// Internally, the index uses a u32, so the index must not exceed
45 /// `u32::MAX`. You can also customize things like the `Debug` impl,
46 /// what traits are derived, and so forth via the macro.
48 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step)]
49 pub fn newtype_index(input: TokenStream) -> TokenStream {
50 newtype::newtype(input)
53 /// Implements the `fluent_messages` macro, which performs compile-time validation of the
54 /// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same
55 /// messages) and generates constants that make using those messages in diagnostics more ergonomic.
57 /// For example, given the following invocation of the macro..
60 /// fluent_messages! {
61 /// typeck => "./typeck.ftl",
64 /// ..where `typeck.ftl` has the following contents..
67 /// typeck-field-multiply-specified-in-initializer =
68 /// field `{$ident}` specified more than once
69 /// .label = used more than once
70 /// .label-previous-use = first use of `{$ident}`
72 /// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and
73 /// will generate the following code:
76 /// pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
77 /// include_str!("./typeck.ftl"),
80 /// mod fluent_generated {
82 /// pub const field_multiply_specified_in_initializer: DiagnosticMessage =
83 /// DiagnosticMessage::fluent("typeck-field-multiply-specified-in-initializer");
84 /// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
85 /// DiagnosticMessage::fluent_attr(
86 /// "typeck-field-multiply-specified-in-initializer",
87 /// "previous-use-label"
92 /// When emitting a diagnostic, the generated constants can be used as follows:
95 /// let mut err = sess.struct_span_err(
97 /// fluent::typeck::field_multiply_specified_in_initializer
99 /// err.span_default_label(span);
101 /// previous_use_span,
102 /// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
107 pub fn fluent_messages(input: TokenStream) -> TokenStream {
108 diagnostics::fluent_messages(input)
111 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
113 [HashStable_Generic, attributes(stable_hasher)] =>
114 hash_stable::hash_stable_generic_derive
117 decl_derive!([Decodable] => serialize::decodable_derive);
118 decl_derive!([Encodable] => serialize::encodable_derive);
119 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
120 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
121 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
122 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
123 decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
124 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
126 [SessionDiagnostic, attributes(
140 suggestion_verbose)] => diagnostics::session_diagnostic_derive
143 [SessionSubdiagnostic, attributes(
144 // struct/variant attributes
155 applicability)] => diagnostics::session_subdiagnostic_derive