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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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" }

0 commit comments

Comments
 (0)