about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/fluent.rs
AgeCommit message (Collapse)AuthorLines
2023-04-18Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`Nilstrieb-336/+0
Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-09Inline format_argsNilstrieb-1/+1
Co-authored-by: Michael Goulet <michael@errs.io>
2023-04-09Some simple `clippy::perf` fixesNilstrieb-1/+1
2023-03-31Don't emit the OS error in a noteest31-3/+6
This makes it possible to make the normalization of the error message more precise, allowing us to not normalize all notes away.
2023-03-31Use std::fs::read_to_file in fluent_messages macroest31-11/+3
2023-03-29Check for escape sequences in Fluent resourcesclubby789-0/+12
2023-02-22errors: generate typed identifiers in each crateDavid Wood-229/+220
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-01-27Detect references to non-existant messages in Fluent resourcesclubby789-2/+32
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-2/+2
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-10-23Generate fluent message constant in a flat module for all cratesNilstrieb-34/+31
This will make it easier to grep for fluent message names.
2022-08-22fluent: point to path containing error instead of module nameXiretza-5/+5
Example error before: error: name `generic_does_not_live_long_enough` does not start with the crate name --> compiler/rustc_error_messages/src/lib.rs:33:17 | 33 | borrowck => "../locales/en-US/borrowck.ftl", | ^^^^^^^^ | = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough` after: error: name `generic_does_not_live_long_enough` does not start with the crate name --> compiler/rustc_error_messages/src/lib.rs:33:17 | 33 | borrowck => "../locales/en-US/borrowck.ftl", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough`
2022-08-22fluent: mandate slug names to be prefixed by crate nameXiretza-5/+17
2022-08-12Change fluent_messages macro to expect _ slugs instead of - slugsest31-5/+27
For the most part, the macro actually worked with _ slugs, but the prefix_something -> prefix::something conversion was not implemented. We don't want to accept - slugs for consistency reasons. We thus error if a name is found with - inside. This ensures a consistent style.
2022-07-20clippy::perf fixesMatthias Krüger-3/+3
2022-07-15macros: support adding warnings to diagsDavid Wood-2/+4
Both diagnostic and subdiagnostic derives were missing the ability to add warnings to diagnostics - this is made more difficult by the `warn` attribute already existing, so this name being unavailable for the derives to use. `#[warn_]` is used instead, which requires special-casing so that `{span_,}warn` is called instead of `{span_,}warn_`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-08Use dashes instead of underscores in fluent namesMichael Goulet-2/+6
2022-06-24macros: use typed identifiers in diag deriveDavid Wood-0/+11
Using typed identifiers instead of strings with the Fluent identifier enables the diagnostic derive to benefit from the compile-time validation that comes with typed identifiers - use of a non-existent Fluent identifier will not compile. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-30errors: simplify referring to fluent attributesDavid Wood-7/+13
To render the message of a Fluent attribute, the identifier of the Fluent message must be known. `DiagnosticMessage::FluentIdentifier` contains both the message's identifier and optionally the identifier of an attribute. Generated constants for each attribute would therefore need to be named uniquely (amongst all error messages) or be able to refer to only the attribute identifier which will be combined with a message identifier later. In this commit, the latter strategy is implemented as part of the `Diagnostic` type's functions for adding subdiagnostics of various kinds. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-24macros: introduce `fluent_messages` macroDavid Wood-0/+254
Adds a new `fluent_messages` macro which performs compile-time validation of the compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same messages) and generates constants that make using those messages in diagnostics more ergonomic. For example, given the following invocation of the macro.. ```ignore (rust) fluent_messages! { typeck => "./typeck.ftl", } ``` ..where `typeck.ftl` has the following contents.. ```fluent typeck-field-multiply-specified-in-initializer = field `{$ident}` specified more than once .label = used more than once .label-previous-use = first use of `{$ident}` ``` ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and will generate the following code: ```ignore (rust) pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[ include_str!("./typeck.ftl"), ]; mod fluent_generated { mod typeck { pub const field_multiply_specified_in_initializer: DiagnosticMessage = DiagnosticMessage::fluent("typeck-field-multiply-specified-in-initializer"); pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage = DiagnosticMessage::fluent_attr( "typeck-field-multiply-specified-in-initializer", "previous-use-label" ); } } ``` When emitting a diagnostic, the generated constants can be used as follows: ```ignore (rust) let mut err = sess.struct_span_err( span, fluent::typeck::field_multiply_specified_in_initializer ); err.span_default_label(span); err.span_label( previous_use_span, fluent::typeck::field_multiply_specified_in_initializer_label_previous_use ); err.emit(); ``` Signed-off-by: David Wood <david.wood@huawei.com>