1 #![feature(allow_internal_unstable)]
2 #![feature(if_let_guard)]
3 #![feature(never_type)]
4 #![feature(proc_macro_diagnostic)]
5 #![feature(proc_macro_span)]
6 #![allow(rustc::default_hash_types)]
7 #![deny(rustc::untranslatable_diagnostic)]
8 #![deny(rustc::diagnostic_outside_of_impl)]
9 #![recursion_limit = "128"]
11 use synstructure::decl_derive;
13 use proc_macro::TokenStream;
26 pub fn rustc_queries(input: TokenStream) -> TokenStream {
27 query::rustc_queries(input)
31 pub fn symbols(input: TokenStream) -> TokenStream {
32 symbols::symbols(input.into()).into()
35 /// Creates a struct type `S` that can be used as an index with
36 /// `IndexVec` and so on.
38 /// There are two ways of interacting with these indices:
40 /// - The `From` impls are the preferred way. So you can do
41 /// `S::from(v)` with a `usize` or `u32`. And you can convert back
42 /// to an integer with `u32::from(s)`.
44 /// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
45 /// to create/return a value.
47 /// Internally, the index uses a u32, so the index must not exceed
48 /// `u32::MAX`. You can also customize things like the `Debug` impl,
49 /// what traits are derived, and so forth via the macro.
51 #[allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)]
52 pub fn newtype_index(input: TokenStream) -> TokenStream {
53 newtype::newtype(input)
56 /// Implements the `fluent_messages` macro, which performs compile-time validation of the
57 /// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same
58 /// messages) and generates constants that make using those messages in diagnostics more ergonomic.
60 /// For example, given the following invocation of the macro..
63 /// fluent_messages! {
64 /// typeck => "./typeck.ftl",
67 /// ..where `typeck.ftl` has the following contents..
70 /// typeck_field_multiply_specified_in_initializer =
71 /// field `{$ident}` specified more than once
72 /// .label = used more than once
73 /// .label_previous_use = first use of `{$ident}`
75 /// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and
76 /// will generate the following code:
79 /// pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
80 /// include_str!("./typeck.ftl"),
83 /// mod fluent_generated {
85 /// pub const field_multiply_specified_in_initializer: DiagnosticMessage =
86 /// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer");
87 /// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
88 /// DiagnosticMessage::fluent_attr(
89 /// "typeck_field_multiply_specified_in_initializer",
90 /// "previous_use_label"
95 /// When emitting a diagnostic, the generated constants can be used as follows:
98 /// let mut err = sess.struct_span_err(
100 /// fluent::typeck::field_multiply_specified_in_initializer
102 /// err.span_default_label(span);
104 /// previous_use_span,
105 /// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
110 pub fn fluent_messages(input: TokenStream) -> TokenStream {
111 diagnostics::fluent_messages(input)
114 decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
116 [HashStable_Generic, attributes(stable_hasher)] =>
117 hash_stable::hash_stable_generic_derive
120 decl_derive!([Decodable] => serialize::decodable_derive);
121 decl_derive!([Encodable] => serialize::encodable_derive);
122 decl_derive!([TyDecodable] => serialize::type_decodable_derive);
123 decl_derive!([TyEncodable] => serialize::type_encodable_derive);
124 decl_derive!([MetadataDecodable] => serialize::meta_decodable_derive);
125 decl_derive!([MetadataEncodable] => serialize::meta_encodable_derive);
126 decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive);
127 decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive);
128 decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
130 [Diagnostic, attributes(
144 suggestion_verbose)] => diagnostics::session_diagnostic_derive
147 [LintDiagnostic, attributes(
161 suggestion_verbose)] => diagnostics::lint_diagnostic_derive
164 [Subdiagnostic, attributes(
165 // struct/variant attributes
174 multipart_suggestion,
175 multipart_suggestion_short,
176 multipart_suggestion_hidden,
177 multipart_suggestion_verbose,
182 applicability)] => diagnostics::session_subdiagnostic_derive