Remove the fallback bundle

This commit is contained in:
Jonathan Brouwer 2026-02-06 20:08:45 +01:00
parent 2289e6cfb7
commit 0db0acd699
No known key found for this signature in database
GPG key ID: 13619B051B673C52
15 changed files with 25 additions and 56 deletions

View file

@ -108,11 +108,9 @@ use crate::session_diagnostics::{
};
pub fn default_translator() -> Translator {
Translator::with_fallback_bundle(DEFAULT_LOCALE_RESOURCES.to_vec(), false)
Translator::new()
}
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[];
/// Exit status code used for successful compilation and help output.
pub const EXIT_SUCCESS: i32 = 0;
@ -219,7 +217,6 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
output_dir: odir,
ice_file,
file_loader: None,
locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(),
lint_caps: Default::default(),
psess_created: None,
hash_untracked_state: None,
@ -1528,7 +1525,7 @@ fn report_ice(
extra_info: fn(&DiagCtxt),
using_internal_features: &AtomicBool,
) {
let translator = default_translator();
let translator = Translator::new();
let emitter =
Box::new(rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter::new(
stderr_destination(rustc_errors::ColorConfig::Auto),

View file

@ -45,7 +45,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
rustc_span::create_default_session_globals_then(|| {
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
sm.new_source_file(filename(&sm, "test.rs"), code.to_owned());
let translator = Translator::with_fallback_bundle(vec![], false);
let translator = Translator::new();
let output = Arc::new(Mutex::new(Vec::new()));
let je = JsonEmitter::new(

View file

@ -34,24 +34,11 @@ pub struct Translator {
/// Localized diagnostics for the locale requested by the user. If no language was requested by
/// the user then this will be `None` and `fallback_fluent_bundle` should be used.
pub fluent_bundle: Option<Arc<FluentBundle>>,
/// Return `FluentBundle` with localized diagnostics for the default locale of the compiler.
/// Used when the user has not requested a specific language or when a localized diagnostic is
/// unavailable for the requested locale.
pub fallback_fluent_bundle: LazyFallbackBundle,
}
impl Translator {
pub fn with_fallback_bundle(
resources: Vec<&'static str>,
with_directionality_markers: bool,
) -> Translator {
Translator {
fluent_bundle: None,
fallback_fluent_bundle: crate::fallback_fluent_bundle(
resources,
with_directionality_markers,
),
}
pub fn new() -> Translator {
Translator { fluent_bundle: None }
}
/// Convert `DiagMessage`s to a string, performing translation if necessary.

View file

@ -332,9 +332,6 @@ pub struct Config {
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
/// The list of fluent resources, used for lints declared with
/// [`Diagnostic`](rustc_errors::Diagnostic) and [`LintDiagnostic`](rustc_errors::LintDiagnostic).
pub locale_resources: Vec<&'static str>,
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
@ -458,7 +455,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
temps_dir,
},
bundle,
config.locale_resources,
config.lint_caps,
target,
util::rustc_version_str().unwrap_or("unknown"),

View file

@ -72,7 +72,6 @@ where
sessopts,
io,
None,
vec![],
Default::default(),
target,
"",

View file

@ -42,7 +42,7 @@ fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
fn create_test_handler(theme: OutputTheme) -> (DiagCtxt, Arc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
let output = Arc::new(Mutex::new(Vec::new()));
let source_map = Arc::new(SourceMap::new(FilePathMapping::empty()));
let translator = Translator::with_fallback_bundle(vec![], false);
let translator = Translator::new();
let shared: Box<dyn Write + Send> = Box::new(Shared { data: output.clone() });
let auto_stream = AutoStream::never(shared);
let dcx = DiagCtxt::new(Box::new(
@ -89,7 +89,7 @@ where
/// Maps a string to tts, using a made-up filename.
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
unwrap_or_emit_fatal(source_str_to_stream(
&psess,
filename(psess.source_map(), "bogofile"),
@ -2239,12 +2239,12 @@ fn sp(a: u32, b: u32) -> Span {
/// Parses a string, return an expression.
fn string_to_expr(source_str: String) -> Box<ast::Expr> {
with_error_checking_parse(source_str, &ParseSess::new(vec![]), |p| p.parse_expr())
with_error_checking_parse(source_str, &ParseSess::new(), |p| p.parse_expr())
}
/// Parses a string, returns an item.
fn string_to_item(source_str: String) -> Option<Box<ast::Item>> {
with_error_checking_parse(source_str, &ParseSess::new(vec![]), |p| {
with_error_checking_parse(source_str, &ParseSess::new(), |p| {
p.parse_item(ForceCollect::No, AllowConstBlockItems::Yes)
})
}
@ -2480,7 +2480,7 @@ let mut fflags: c_int = wb();
#[test]
fn crlf_doc_comments() {
create_default_session_globals_then(|| {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let name_1 = FileName::Custom("crlf_source_1".to_string());
let source = "/// doc comment\r\nfn foo() {}".to_string();
@ -2515,7 +2515,7 @@ fn ttdelim_span() {
}
create_default_session_globals_then(|| {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let expr = parse_expr_from_source_str(
filename(psess.source_map(), "foo"),
"foo!( fn main() { body } )".to_string(),
@ -2551,7 +2551,7 @@ fn look_ahead() {
let sym_S = Symbol::intern("S");
let raw_no = IdentIsRaw::No;
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let mut p = string_to_parser(&psess, "fn f(x: u32) { x } struct S;".to_string());
// Current position is the `fn`.
@ -2626,7 +2626,7 @@ fn look_ahead_non_outermost_stream() {
let sym_S = Symbol::intern("S");
let raw_no = IdentIsRaw::No;
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let mut p = string_to_parser(&psess, "mod m { fn f(x: u32) { x } struct S; }".to_string());
// Move forward to the `fn`, which is not within the outermost token
@ -2658,7 +2658,7 @@ fn look_ahead_non_outermost_stream() {
#[test]
fn debug_lookahead() {
create_default_session_globals_then(|| {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let mut p = string_to_parser(&psess, "fn f(x: u32) { x } struct S;".to_string());
// Current position is the `fn`.
@ -2879,7 +2879,7 @@ fn debug_lookahead() {
#[test]
fn out_of_line_mod() {
create_default_session_globals_then(|| {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let item = parse_item_from_source_str(
filename(psess.source_map(), "foo"),
"mod foo { struct S; mod this_does_not_exist; }".to_owned(),

View file

@ -280,8 +280,8 @@ pub struct ParseSess {
impl ParseSess {
/// Used for testing.
pub fn new(locale_resources: Vec<&'static str>) -> Self {
let translator = Translator::with_fallback_bundle(locale_resources, false);
pub fn new() -> Self {
let translator = Translator::new();
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = Box::new(
AnnotateSnippetEmitter::new(stderr_destination(ColorConfig::Auto), translator)
@ -314,7 +314,7 @@ impl ParseSess {
}
pub fn emitter_with_note(note: String) -> Self {
let translator = Translator::with_fallback_bundle(vec![], false);
let translator = Translator::new();
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = Box::new(AnnotateSnippetEmitter::new(
stderr_destination(ColorConfig::Auto),

View file

@ -19,7 +19,7 @@ use rustc_errors::timings::TimingSectionHandler;
use rustc_errors::translation::Translator;
use rustc_errors::{
Diag, DiagCtxt, DiagCtxtHandle, DiagMessage, Diagnostic, ErrorGuaranteed, FatalAbort,
TerminalUrl, fallback_fluent_bundle,
TerminalUrl,
};
use rustc_hir::limit::Limit;
use rustc_macros::HashStable_Generic;
@ -967,7 +967,6 @@ pub fn build_session(
sopts: config::Options,
io: CompilerIO,
fluent_bundle: Option<Arc<rustc_errors::FluentBundle>>,
fluent_resources: Vec<&'static str>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
target: Target,
cfg_version: &'static str,
@ -985,13 +984,7 @@ pub fn build_session(
let cap_lints_allow = sopts.lint_cap.is_some_and(|cap| cap == lint::Allow);
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
let translator = Translator {
fluent_bundle,
fallback_fluent_bundle: fallback_fluent_bundle(
fluent_resources,
sopts.unstable_opts.translate_directionality_markers,
),
};
let translator = Translator { fluent_bundle };
let source_map = rustc_span::source_map::get_source_map().unwrap();
let emitter = default_emitter(&sopts, Arc::clone(&source_map), translator);
@ -1430,7 +1423,7 @@ impl EarlyDiagCtxt {
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
// FIXME(#100717): early errors aren't translated at the moment, so this is fine, but it will
// need to reference every crate that might emit an early error for translation to work.
let translator = Translator::with_fallback_bundle(vec![], false);
let translator = Translator::new();
let emitter: Box<DynEmitter> = match output {
config::ErrorOutputType::HumanReadable { kind, color_config } => match kind {
HumanReadableErrorType { short, unicode } => Box::new(

View file

@ -63,7 +63,7 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option<String
let snippet = source_map.span_to_snippet(span).ok()?;
// Create a Parser.
let psess = ParseSess::new(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec());
let psess = ParseSess::new();
let file_name = FileName::macro_expansion_source_code(&snippet);
let mut parser = match rustc_parse::new_parser_from_source_str(
&psess,

View file

@ -289,7 +289,6 @@ pub(crate) fn create_config(
output_file: None,
output_dir: None,
file_loader: None,
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
lint_caps,
psess_created: None,
hash_untracked_state: None,

View file

@ -188,7 +188,6 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
output_file: None,
output_dir: None,
file_loader: None,
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
lint_caps,
psess_created: None,
hash_untracked_state: None,

View file

@ -29,7 +29,7 @@ pub fn main() {
}
fn parse() {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
let path = Path::new(file!());
let path = path.canonicalize().unwrap();

View file

@ -219,7 +219,7 @@ fn main() {
}
fn run() {
let psess = ParseSess::new(vec![]);
let psess = ParseSess::new();
iter_exprs(2, &mut |mut e| {
// If the pretty printer is correct, then `parse(print(e))` should be identical to `e`,

View file

@ -196,7 +196,7 @@ fn main() -> ExitCode {
};
rustc_span::create_default_session_globals_then(|| {
let psess = &ParseSess::new(vec![]);
let psess = &ParseSess::new();
for &source_code in EXPRS {
let Some(expr) = parse_expr(psess, source_code) else {

View file

@ -64,7 +64,6 @@ fn compile(code: String, output: PathBuf, sysroot: Sysroot, linker: Option<&Path
output_dir: None,
ice_file: None,
file_loader: None,
locale_resources: Vec::new(),
lint_caps: Default::default(),
psess_created: None,
hash_untracked_state: None,