]>
git.proxmox.com Git - rustc.git/blob - compiler/rustc_fluent_macro/src/lib.rs
1 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3 #![allow(internal_features)]
4 #![feature(rustdoc_internals)]
5 #![feature(proc_macro_diagnostic)]
6 #![feature(proc_macro_span)]
7 #![deny(rustc::untranslatable_diagnostic)]
8 #![deny(rustc::diagnostic_outside_of_impl)]
9 #![allow(rustc::default_hash_types)]
11 use proc_macro
::TokenStream
;
15 /// Implements the `fluent_messages` macro, which performs compile-time validation of the
16 /// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same
17 /// messages) and generates constants that make using those messages in diagnostics more ergonomic.
19 /// For example, given the following invocation of the macro..
22 /// fluent_messages! { "./typeck.ftl" }
24 /// ..where `typeck.ftl` has the following contents..
27 /// typeck_field_multiply_specified_in_initializer =
28 /// field `{$ident}` specified more than once
29 /// .label = used more than once
30 /// .label_previous_use = first use of `{$ident}`
32 /// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and
33 /// will generate the following code:
36 /// pub static DEFAULT_LOCALE_RESOURCE: &'static [&'static str] = include_str!("./typeck.ftl");
38 /// mod fluent_generated {
40 /// pub const field_multiply_specified_in_initializer: DiagnosticMessage =
41 /// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer");
42 /// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
43 /// DiagnosticMessage::fluent_attr(
44 /// "typeck_field_multiply_specified_in_initializer",
45 /// "previous_use_label"
50 /// When emitting a diagnostic, the generated constants can be used as follows:
53 /// let mut err = sess.struct_span_err(
55 /// fluent::typeck::field_multiply_specified_in_initializer
57 /// err.span_default_label(span);
59 /// previous_use_span,
60 /// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
65 /// Note: any crate using this macro must also have a dependency on
66 /// `rustc_errors`, because the generated code refers to things from that
69 pub fn fluent_messages(input
: TokenStream
) -> TokenStream
{
70 fluent
::fluent_messages(input
)