Commit d473024
authored
Rollup merge of rust-lang#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`File tree
101 files changed
+2911
-1071
lines changed- compiler
- rustc_borrowck/src
- diagnostics
- rustc_builtin_macros/src
- rustc_codegen_ssa/src/back
- rustc_driver/src
- rustc_error_messages
- locales/en-US
- src
- rustc_errors
- src
- json
- rustc_expand/src
- mbe
- rustc_hir
- src
- rustc_infer/src
- infer/error_reporting
- nice_region_error
- traits/error_reporting
- rustc_interface/src
- rustc_lint_defs
- src
- rustc_lint/src
- rustc_macros/src
- rustc_middle/src
- ty
- util
- rustc_mir_build/src/thir/pattern
- rustc_parse/src/parser
- rustc_passes/src
- rustc_query_system/src/query
- rustc_resolve/src
- late
- rustc_serialize/src
- rustc_session/src
- rustc_span/src
- rustc_trait_selection/src/traits
- error_reporting
- rustc_typeck/src
- astconv
- check
- fn_ctxt
- method
- structured_errors
- src
- librustdoc
- passes
- test
- run-make/translation
- ui-fulldeps
- ui
- error-codes
- tools
- clippy
- clippy_lints/src
- loops
- clippy_utils/src
- src
- rustfmt/src/parse
- tidy/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
101 files changed
+2911
-1071
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1238 | 1238 | | |
1239 | 1239 | | |
1240 | 1240 | | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
1241 | 1275 | | |
1242 | 1276 | | |
1243 | 1277 | | |
| |||
1782 | 1816 | | |
1783 | 1817 | | |
1784 | 1818 | | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
1785 | 1839 | | |
1786 | 1840 | | |
1787 | 1841 | | |
| |||
2812 | 2866 | | |
2813 | 2867 | | |
2814 | 2868 | | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
2815 | 2875 | | |
2816 | 2876 | | |
2817 | 2877 | | |
| |||
3645 | 3705 | | |
3646 | 3706 | | |
3647 | 3707 | | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
3648 | 3723 | | |
3649 | 3724 | | |
3650 | 3725 | | |
3651 | 3726 | | |
3652 | 3727 | | |
3653 | 3728 | | |
3654 | 3729 | | |
| 3730 | + | |
3655 | 3731 | | |
3656 | 3732 | | |
3657 | 3733 | | |
| |||
3708 | 3784 | | |
3709 | 3785 | | |
3710 | 3786 | | |
| 3787 | + | |
3711 | 3788 | | |
3712 | 3789 | | |
3713 | 3790 | | |
| |||
3864 | 3941 | | |
3865 | 3942 | | |
3866 | 3943 | | |
| 3944 | + | |
3867 | 3945 | | |
3868 | 3946 | | |
3869 | 3947 | | |
| |||
4573 | 4651 | | |
4574 | 4652 | | |
4575 | 4653 | | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
4576 | 4660 | | |
4577 | 4661 | | |
4578 | 4662 | | |
| |||
5104 | 5188 | | |
5105 | 5189 | | |
5106 | 5190 | | |
| 5191 | + | |
| 5192 | + | |
| 5193 | + | |
| 5194 | + | |
| 5195 | + | |
| 5196 | + | |
5107 | 5197 | | |
5108 | 5198 | | |
5109 | 5199 | | |
| |||
5262 | 5352 | | |
5263 | 5353 | | |
5264 | 5354 | | |
| 5355 | + | |
| 5356 | + | |
| 5357 | + | |
| 5358 | + | |
| 5359 | + | |
| 5360 | + | |
| 5361 | + | |
| 5362 | + | |
| 5363 | + | |
5265 | 5364 | | |
5266 | 5365 | | |
5267 | 5366 | | |
| |||
5316 | 5415 | | |
5317 | 5416 | | |
5318 | 5417 | | |
| 5418 | + | |
| 5419 | + | |
| 5420 | + | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
| 5432 | + | |
| 5433 | + | |
| 5434 | + | |
| 5435 | + | |
| 5436 | + | |
| 5437 | + | |
| 5438 | + | |
| 5439 | + | |
| 5440 | + | |
| 5441 | + | |
| 5442 | + | |
| 5443 | + | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
| 5448 | + | |
| 5449 | + | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
| 5453 | + | |
| 5454 | + | |
| 5455 | + | |
| 5456 | + | |
| 5457 | + | |
| 5458 | + | |
| 5459 | + | |
| 5460 | + | |
5319 | 5461 | | |
5320 | 5462 | | |
5321 | 5463 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
450 | 452 | | |
451 | 453 | | |
452 | 454 | | |
| |||
455 | 457 | | |
456 | 458 | | |
457 | 459 | | |
458 | | - | |
| 460 | + | |
| 461 | + | |
459 | 462 | | |
460 | 463 | | |
461 | 464 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1707 | 1707 | | |
1708 | 1708 | | |
1709 | 1709 | | |
| 1710 | + | |
1710 | 1711 | | |
1711 | | - | |
| 1712 | + | |
1712 | 1713 | | |
1713 | 1714 | | |
1714 | 1715 | | |
1715 | 1716 | | |
1716 | 1717 | | |
1717 | | - | |
| 1718 | + | |
1718 | 1719 | | |
1719 | 1720 | | |
1720 | 1721 | | |
1721 | 1722 | | |
1722 | 1723 | | |
1723 | 1724 | | |
| 1725 | + | |
1724 | 1726 | | |
1725 | 1727 | | |
1726 | 1728 | | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
1727 | 1737 | | |
1728 | 1738 | | |
1729 | 1739 | | |
| |||
1754 | 1764 | | |
1755 | 1765 | | |
1756 | 1766 | | |
1757 | | - | |
1758 | | - | |
1759 | | - | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
1760 | 1770 | | |
1761 | 1771 | | |
1762 | 1772 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1172 | 1172 | | |
1173 | 1173 | | |
1174 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
1175 | 1177 | | |
1176 | 1178 | | |
1177 | 1179 | | |
| 1180 | + | |
| 1181 | + | |
1178 | 1182 | | |
1179 | 1183 | | |
1180 | 1184 | | |
| |||
1209 | 1213 | | |
1210 | 1214 | | |
1211 | 1215 | | |
1212 | | - | |
| 1216 | + | |
1213 | 1217 | | |
1214 | 1218 | | |
1215 | 1219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments