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"]
12 use synstructure::decl_derive;
14 use proc_macro::TokenStream;
27 pub fn rustc_queries(input: TokenStream) -> TokenStream {
28 query::rustc_queries(input)
32 pub fn symbols(input: TokenStream) -> TokenStream {
33 symbols::symbols(input.into()).into()
36 /// Creates a struct type `S` that can be used as an index with
37 /// `IndexVec` and so on.
39 /// There are two ways of interacting with these indices:
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)`.
45 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
46 /// to create/return a value.
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.
52 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)]
53 pub fn newtype_index(input: TokenStream) -> TokenStream {
54 newtype::newtype(input)
57 /// Implements the `fluent_messages` macro, which performs compile-time validation of the
58 /// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same
59 /// messages) and generates constants that make using those messages in diagnostics more ergonomic.
61 /// For example, given the following invocation of the macro..
64 /// fluent_messages! {
65 /// typeck => "./typeck.ftl",
68 /// ..where `typeck.ftl` has the following contents..
71 /// typeck_field_multiply_specified_in_initializer =
72 /// field `{$ident}` specified more than once
73 /// .label = used more than once
74 /// .label_previous_use = first use of `{$ident}`
76 /// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and
77 /// will generate the following code:
80 /// pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
81 /// include_str!("./typeck.ftl"),
84 /// mod fluent_generated {
86 /// pub const field_multiply_specified_in_initializer: DiagnosticMessage =
87 /// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer");
88 /// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
89 /// DiagnosticMessage::fluent_attr(
90 /// "typeck_field_multiply_specified_in_initializer",
91 /// "previous_use_label"
96 /// When emitting a diagnostic, the generated constants can be used as follows:
99 /// let mut err = sess.struct_span_err(
101 /// fluent::typeck::field_multiply_specified_in_initializer
103 /// err.span_default_label(span);
105 /// previous_use_span,
106 /// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
111 pub fn fluent_messages(input: TokenStream) -> TokenStream {
112 diagnostics::fluent_messages(input)
115 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
117 [HashStable_Generic, attributes(stable_hasher)] =>
118 hash_stable::hash_stable_generic_derive
121 decl_derive!([Decodable] => serialize::decodable_derive);
122 decl_derive!([Encodable] => serialize::encodable_derive);
123 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
124 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
125 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
126 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
127 decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
128 decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive);
129 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
131 [Diagnostic, attributes(
145 suggestion_verbose)] => diagnostics::session_diagnostic_derive
148 [LintDiagnostic, attributes(
162 suggestion_verbose)] => diagnostics::lint_diagnostic_derive
165 [Subdiagnostic, attributes(
166 // struct/variant attributes
175 multipart_suggestion,
176 multipart_suggestion_short,
177 multipart_suggestion_hidden,
178 multipart_suggestion_verbose,
183 applicability)] => diagnostics::session_subdiagnostic_derive