Skip to content

Commit b869e84

Browse files
committed
Auto merge of rust-lang#103042 - davidtwco:translation-distributed-ftl, r=oli-obk
errors: generate typed identifiers in each crate 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. There are advantages and disadvantages to this change.. #### Advantages - Changing a diagnostic now only recompiles the crate for that diagnostic and those crates that depend on it, rather than `rustc_error_messages` and all crates thereafter. - This approach can be used to support first-party crates that want to supply translatable diagnostics (e.g. `rust-lang/thorin` in rust-lang#102612 (comment), cc `@JhonnyBillM)` - We can extend this a little so that tools built using rustc internals (like clippy or rustdoc) can add their own diagnostic resources (much more easily than those resources needing to be available to `rustc_error_messages`) #### Disadvantages - Crates can only refer to the diagnostic messages defined in the current crate (or those from dependencies), rather than all diagnostic messages. - `rustc_driver` (or some other crate we create for this purpose) has to directly depend on *everything* that has error messages. - It already transitively depended on all these crates. #### Pending work - [x] I don't know how to make `rustc_codegen_gcc`'s translated diagnostics work with this approach - because `rustc_driver` can't depend on that crate and so can't get its resources to provide to the diagnostic emission. I don't really know how the alternative codegen backends are actually wired up to the compiler at all. - [x] Update `triagebot.toml` to track the moved FTL files. r? `@compiler-errors` cc rust-lang#100717
2 parents 3b4d6e0 + 2625518 commit b869e84

File tree

156 files changed

+1739
-1407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1739
-1407
lines changed

Cargo.lock

+21
Original file line numberDiff line numberDiff line change
@@ -3930,26 +3930,47 @@ version = "0.0.0"
39303930
dependencies = [
39313931
"libc",
39323932
"rustc_ast",
3933+
"rustc_ast_lowering",
3934+
"rustc_ast_passes",
39333935
"rustc_ast_pretty",
3936+
"rustc_attr",
3937+
"rustc_borrowck",
3938+
"rustc_builtin_macros",
39343939
"rustc_codegen_ssa",
3940+
"rustc_const_eval",
39353941
"rustc_data_structures",
39363942
"rustc_error_codes",
3943+
"rustc_error_messages",
39373944
"rustc_errors",
3945+
"rustc_expand",
39383946
"rustc_feature",
39393947
"rustc_hir",
39403948
"rustc_hir_analysis",
39413949
"rustc_hir_pretty",
3950+
"rustc_hir_typeck",
3951+
"rustc_incremental",
3952+
"rustc_infer",
39423953
"rustc_interface",
39433954
"rustc_lint",
39443955
"rustc_log",
39453956
"rustc_macros",
39463957
"rustc_metadata",
39473958
"rustc_middle",
3959+
"rustc_mir_build",
3960+
"rustc_mir_dataflow",
3961+
"rustc_monomorphize",
39483962
"rustc_parse",
3963+
"rustc_passes",
39493964
"rustc_plugin_impl",
3965+
"rustc_privacy",
3966+
"rustc_query_system",
3967+
"rustc_resolve",
39503968
"rustc_session",
39513969
"rustc_span",
3970+
"rustc_symbol_mangling",
39523971
"rustc_target",
3972+
"rustc_trait_selection",
3973+
"rustc_ty_utils",
39533974
"serde_json",
39543975
"tracing",
39553976
"winapi",

compiler/rustc_ast_lowering/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub struct InclusiveRangeWithNoEnd {
339339
#[derive(Diagnostic, Clone, Copy)]
340340
#[diag(ast_lowering_trait_fn_async, code = "E0706")]
341341
#[note]
342-
#[note(note2)]
342+
#[note(ast_lowering_note2)]
343343
pub struct TraitFnAsync {
344344
#[primary_span]
345345
pub fn_span: Span,

compiler/rustc_ast_lowering/src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@ use rustc_data_structures::fx::FxHashMap;
5252
use rustc_data_structures::sorted_map::SortedMap;
5353
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5454
use rustc_data_structures::sync::Lrc;
55-
use rustc_errors::{DiagnosticArgFromDisplay, Handler, StashKey};
55+
use rustc_errors::{
56+
DiagnosticArgFromDisplay, DiagnosticMessage, Handler, StashKey, SubdiagnosticMessage,
57+
};
5658
use rustc_hir as hir;
5759
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5860
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
5961
use rustc_hir::definitions::DefPathData;
6062
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
6163
use rustc_index::vec::{Idx, IndexVec};
62-
use rustc_middle::span_bug;
63-
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
64+
use rustc_macros::fluent_messages;
65+
use rustc_middle::{
66+
span_bug,
67+
ty::{ResolverAstLowering, TyCtxt},
68+
};
6469
use rustc_session::parse::feature_err;
6570
use rustc_span::hygiene::MacroKind;
6671
use rustc_span::source_map::DesugaringKind;
@@ -87,6 +92,8 @@ mod lifetime_collector;
8792
mod pat;
8893
mod path;
8994

95+
fluent_messages! { "../locales/en-US.ftl" }
96+
9097
struct LoweringContext<'a, 'hir> {
9198
tcx: TyCtxt<'hir>,
9299
resolver: &'a mut ResolverAstLowering,

compiler/rustc_ast_passes/src/ast_validation.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::walk_list;
1313
use rustc_ast::*;
1414
use rustc_ast_pretty::pprust::{self, State};
1515
use rustc_data_structures::fx::FxHashMap;
16-
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
16+
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
1717
use rustc_macros::Subdiagnostic;
1818
use rustc_parse::validate_attr;
1919
use rustc_session::lint::builtin::{
@@ -30,6 +30,7 @@ use std::ops::{Deref, DerefMut};
3030
use thin_vec::thin_vec;
3131

3232
use crate::errors::*;
33+
use crate::fluent_generated as fluent;
3334

3435
const MORE_EXTERN: &str =
3536
"for more information, visit https://doc.rust-lang.org/std/keyword.extern.html";
@@ -1723,12 +1724,12 @@ pub(crate) enum ForbiddenLetReason {
17231724
/// `let` is not valid and the source environment is not important
17241725
GenericForbidden,
17251726
/// A let chain with the `||` operator
1726-
#[note(not_supported_or)]
1727+
#[note(ast_passes_not_supported_or)]
17271728
NotSupportedOr(#[primary_span] Span),
17281729
/// A let chain with invalid parentheses
17291730
///
17301731
/// For example, `let 1 = 1 && (expr && expr)` is allowed
17311732
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
1732-
#[note(not_supported_parentheses)]
1733+
#[note(ast_passes_not_supported_parentheses)]
17331734
NotSupportedParentheses(#[primary_span] Span),
17341735
}

compiler/rustc_ast_passes/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ pub struct InvalidLabel {
5050
pub struct InvalidVisibility {
5151
#[primary_span]
5252
pub span: Span,
53-
#[label(implied)]
53+
#[label(ast_passes_implied)]
5454
pub implied: Option<Span>,
5555
#[subdiagnostic]
5656
pub note: Option<InvalidVisibilityNote>,
5757
}
5858

5959
#[derive(Subdiagnostic)]
6060
pub enum InvalidVisibilityNote {
61-
#[note(individual_impl_items)]
61+
#[note(ast_passes_individual_impl_items)]
6262
IndividualImplItems,
63-
#[note(individual_foreign_items)]
63+
#[note(ast_passes_individual_foreign_items)]
6464
IndividualForeignItems,
6565
}
6666

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> PostExpansionVisitor<'a> {
157157
&self.sess.parse_sess,
158158
sym::non_lifetime_binders,
159159
non_lt_param_spans,
160-
rustc_errors::fluent::ast_passes_forbidden_non_lifetime_param,
160+
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param,
161161
)
162162
.emit();
163163
}

compiler/rustc_ast_passes/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
#![feature(let_chains)]
1212
#![recursion_limit = "256"]
1313

14+
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
15+
use rustc_macros::fluent_messages;
16+
1417
pub mod ast_validation;
1518
mod errors;
1619
pub mod feature_gate;
1720
pub mod node_count;
1821
pub mod show_span;
22+
23+
fluent_messages! { "../locales/en-US.ftl" }

compiler/rustc_attr/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#[macro_use]
1212
extern crate rustc_macros;
1313

14+
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
15+
use rustc_macros::fluent_messages;
16+
1417
mod builtin;
1518
mod session_diagnostics;
1619

@@ -22,3 +25,5 @@ pub use StabilityLevel::*;
2225
pub use rustc_ast::attr::*;
2326

2427
pub(crate) use rustc_ast::HashStableContext;
28+
29+
fluent_messages! { "../locales/en-US.ftl" }

compiler/rustc_attr/src/session_diagnostics.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use std::num::IntErrorKind;
22

33
use rustc_ast as ast;
44
use rustc_errors::{
5-
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
5+
error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
66
};
77
use rustc_macros::Diagnostic;
88
use rustc_span::{Span, Symbol};
99

10+
use crate::fluent_generated as fluent;
1011
use crate::UnsupportedLiteralReason;
1112

1213
#[derive(Diagnostic)]
@@ -59,7 +60,7 @@ impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> {
5960
);
6061
diag.set_arg("item", self.item);
6162
diag.set_arg("expected", expected.join(", "));
62-
diag.span_label(self.span, fluent::label);
63+
diag.span_label(self.span, fluent::attr_label);
6364
diag
6465
}
6566
}
@@ -99,31 +100,31 @@ pub(crate) struct InvalidIssueString {
99100
// translatable.
100101
#[derive(Subdiagnostic)]
101102
pub(crate) enum InvalidIssueStringCause {
102-
#[label(must_not_be_zero)]
103+
#[label(attr_must_not_be_zero)]
103104
MustNotBeZero {
104105
#[primary_span]
105106
span: Span,
106107
},
107108

108-
#[label(empty)]
109+
#[label(attr_empty)]
109110
Empty {
110111
#[primary_span]
111112
span: Span,
112113
},
113114

114-
#[label(invalid_digit)]
115+
#[label(attr_invalid_digit)]
115116
InvalidDigit {
116117
#[primary_span]
117118
span: Span,
118119
},
119120

120-
#[label(pos_overflow)]
121+
#[label(attr_pos_overflow)]
121122
PosOverflow {
122123
#[primary_span]
123124
span: Span,
124125
},
125126

126-
#[label(neg_overflow)]
127+
#[label(attr_neg_overflow)]
127128
NegOverflow {
128129
#[primary_span]
129130
span: Span,
@@ -275,7 +276,7 @@ pub(crate) struct IncorrectReprFormatGeneric<'a> {
275276

276277
#[derive(Subdiagnostic)]
277278
pub(crate) enum IncorrectReprFormatGenericCause<'a> {
278-
#[suggestion(suggestion, code = "{name}({int})", applicability = "machine-applicable")]
279+
#[suggestion(attr_suggestion, code = "{name}({int})", applicability = "machine-applicable")]
279280
Int {
280281
#[primary_span]
281282
span: Span,
@@ -287,7 +288,7 @@ pub(crate) enum IncorrectReprFormatGenericCause<'a> {
287288
int: u128,
288289
},
289290

290-
#[suggestion(suggestion, code = "{name}({symbol})", applicability = "machine-applicable")]
291+
#[suggestion(attr_suggestion, code = "{name}({symbol})", applicability = "machine-applicable")]
291292
Symbol {
292293
#[primary_span]
293294
span: Span,

compiler/rustc_borrowck/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ extern crate tracing;
2020
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2121
use rustc_data_structures::graph::dominators::Dominators;
2222
use rustc_data_structures::vec_map::VecMap;
23-
use rustc_errors::{Diagnostic, DiagnosticBuilder};
23+
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage};
2424
use rustc_hir as hir;
2525
use rustc_hir::def_id::LocalDefId;
2626
use rustc_index::bit_set::ChunkedBitSet;
2727
use rustc_index::vec::IndexVec;
2828
use rustc_infer::infer::{
2929
DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
3030
};
31+
use rustc_macros::fluent_messages;
3132
use rustc_middle::mir::{
3233
traversal, Body, ClearCrossCrate, Local, Location, Mutability, NonDivergingIntrinsic, Operand,
3334
Place, PlaceElem, PlaceRef, VarDebugInfoContents,
@@ -99,6 +100,8 @@ use places_conflict::{places_conflict, PlaceConflictBias};
99100
use region_infer::RegionInferenceContext;
100101
use renumber::RegionCtxt;
101102

103+
fluent_messages! { "../locales/en-US.ftl" }
104+
102105
// FIXME(eddyb) perhaps move this somewhere more centrally.
103106
#[derive(Debug)]
104107
struct Upvar<'tcx> {

compiler/rustc_borrowck/src/session_diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) struct VarNeedNotMut {
5555
#[derive(Diagnostic)]
5656
#[diag(borrowck_var_cannot_escape_closure)]
5757
#[note]
58-
#[note(cannot_escape)]
58+
#[note(borrowck_cannot_escape)]
5959
pub(crate) struct FnMutError {
6060
#[primary_span]
6161
pub span: Span,
@@ -223,7 +223,7 @@ pub(crate) struct MoveBorrow<'a> {
223223
pub borrow_place: &'a str,
224224
pub value_place: &'a str,
225225
#[primary_span]
226-
#[label(move_label)]
226+
#[label(borrowck_move_label)]
227227
pub span: Span,
228228
#[label]
229229
pub borrow_span: Span,

compiler/rustc_builtin_macros/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ extern crate tracing;
2121

2222
use crate::deriving::*;
2323

24+
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
2425
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
2526
use rustc_expand::proc_macro::BangProcMacro;
27+
use rustc_macros::fluent_messages;
2628
use rustc_span::symbol::sym;
2729

2830
mod alloc_error_handler;
@@ -54,6 +56,8 @@ pub mod proc_macro_harness;
5456
pub mod standard_library_imports;
5557
pub mod test_harness;
5658

59+
fluent_messages! { "../locales/en-US.ftl" }
60+
5761
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
5862
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
5963
macro register_bang($($name:ident: $f:expr,)*) {

compiler/rustc_codegen_cranelift/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ pub struct CraneliftCodegenBackend {
172172
}
173173

174174
impl CodegenBackend for CraneliftCodegenBackend {
175+
fn locale_resource(&self) -> &'static str {
176+
// FIXME(rust-lang/rust#100717) - cranelift codegen backend is not yet translated
177+
""
178+
}
179+
175180
fn init(&self, sess: &Session) {
176181
use rustc_session::config::Lto;
177182
match sess.lto() {

compiler/rustc_codegen_gcc/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul
7373
use rustc_codegen_ssa::target_features::supported_target_features;
7474
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
7575
use rustc_data_structures::fx::FxHashMap;
76-
use rustc_errors::{ErrorGuaranteed, Handler};
76+
use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, SubdiagnosticMessage};
77+
use rustc_macros::fluent_messages;
7778
use rustc_metadata::EncodedMetadata;
7879
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
7980
use rustc_middle::ty::TyCtxt;
@@ -84,6 +85,8 @@ use rustc_span::Symbol;
8485
use rustc_span::fatal_error::FatalError;
8586
use tempfile::TempDir;
8687

88+
fluent_messages! { "../locales/en-US.ftl" }
89+
8790
pub struct PrintOnPanic<F: Fn() -> String>(pub F);
8891

8992
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
@@ -100,6 +103,10 @@ pub struct GccCodegenBackend {
100103
}
101104

102105
impl CodegenBackend for GccCodegenBackend {
106+
fn locale_resource(&self) -> &'static str {
107+
crate::DEFAULT_LOCALE_RESOURCE
108+
}
109+
103110
fn init(&self, sess: &Session) {
104111
if sess.lto() != Lto::No {
105112
sess.emit_warning(LTONotSupported {});

compiler/rustc_codegen_llvm/src/errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::borrow::Cow;
22
use std::ffi::CString;
33
use std::path::Path;
44

5+
use crate::fluent_generated as fluent;
56
use rustc_data_structures::small_c_str::SmallCStr;
67
use rustc_errors::{
7-
fluent, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
8+
DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
89
};
910
use rustc_macros::{Diagnostic, Subdiagnostic};
1011
use rustc_span::Span;
@@ -27,9 +28,9 @@ pub(crate) struct UnknownCTargetFeature<'a> {
2728

2829
#[derive(Subdiagnostic)]
2930
pub(crate) enum PossibleFeature<'a> {
30-
#[help(possible_feature)]
31+
#[help(codegen_llvm_possible_feature)]
3132
Some { rust_feature: &'a str },
32-
#[help(consider_filing_feature_request)]
33+
#[help(codegen_llvm_consider_filing_feature_request)]
3334
None,
3435
}
3536

0 commit comments

Comments
 (0)