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