-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #95512 - davidtwco:diagnostic-translation, r=oli-obk
diagnostics: translation infrastructure An implementation of the infrastructure required to have translatable diagnostic messages. - Introduces a `DiagnosticMessage` type which can represent both the current non-translatable messages and identifiers for [Fluent](https://projectfluent.org/). - Modifies current diagnostic API so that existing calls still work but `DiagnosticMessage`s can be provided too. - Adds support for always loading a "fallback bundle" containing the English diagnostic messages, which are used when a `DiagnosticMessage::FluentIdentifier` is used in a diagnostic being emitted. - Adds support for loading a "primary bundle" which contains the user's preferred language translation, and is used preferentially when it contains a diagnostic message being emitted. Primary bundles are loaded either from the path provided to `-Ztranslate-alternate-ftl` (for testing), or from the sysroot at `$sysroot/locale/$locale/*.ftl` given a locale with `-Ztranslate-lang` (which is parsed as a language identifier). - Adds "diagnostic args" which enable normally-interpolated variables to be made available as variables for Fluent messages to use. - Updates `#[derive(SessionDiagnostic)]` so that it can only be used for translatable diagnostics and update the handful of diagnostics which used the derive to be translatable. For example, the following diagnostic... ```rust #[derive(SessionDiagnostic)] #[error = "E0195"] pub struct LifetimesOrBoundsMismatchOnTrait { #[message = "lifetime parameters or bounds on {item_kind} `{ident}` do not match the trait declaration"] #[label = "lifetimes do not match {item_kind} in trait"] pub span: Span, #[label = "lifetimes in impl do not match this {item_kind} in trait"] pub generics_span: Option<Span>, pub item_kind: &'static str, pub ident: Ident, } ``` ...becomes... ```rust #[derive(SessionDiagnostic)] #[error(code = "E0195", slug = "typeck-lifetimes-or-bounds-mismatch-on-trait")] pub struct LifetimesOrBoundsMismatchOnTrait { #[primary_span] #[label] pub span: Span, #[label = "generics-label"] pub generics_span: Option<Span>, pub item_kind: &'static str, pub ident: Ident, } ``` ```fluent typeck-lifetimes-or-bounds-mismatch-on-trait = lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration .label = lifetimes do not match {$item_kind} in trait .generics-label = lifetimes in impl do not match this {$item_kind} in trait ``` r? `@estebank` cc `@oli-obk` `@Manishearth`
- Loading branch information
Showing
101 changed files
with
2,911 additions
and
1,071 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "rustc_error_messages" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
doctest = false | ||
|
||
[dependencies] | ||
fluent-bundle = "0.15.2" | ||
fluent-syntax = "0.11" | ||
intl-memoizer = "0.5.1" | ||
rustc_data_structures = { path = "../rustc_data_structures" } | ||
rustc_serialize = { path = "../rustc_serialize" } | ||
rustc_span = { path = "../rustc_span" } | ||
rustc_macros = { path = "../rustc_macros" } | ||
tracing = "0.1" | ||
unic-langid = { version = "0.9.0", features = ["macros"] } |
Oops, something went wrong.