Skip to content

Commit 141f840

Browse files
committed
errors: don't try load default locale from sysroot
If the user requests a diagnostic locale of "en-US" then it doesn't make sense to try and load that from the `$sysroot` because it is just the default built-in locale. Signed-off-by: David Wood <[email protected]>
1 parent 22685b9 commit 141f840

File tree

1 file changed

+9
-3
lines changed
  • compiler/rustc_error_messages/src

1 file changed

+9
-3
lines changed

compiler/rustc_error_messages/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(let_chains)]
12
#![feature(path_try_exists)]
23

34
use fluent_bundle::FluentResource;
@@ -105,9 +106,12 @@ pub fn fluent_bundle(
105106
return Ok(None);
106107
}
107108

109+
let fallback_locale = langid!("en-US");
110+
let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
111+
108112
// If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
109113
// provided locale.
110-
let locale = requested_locale.clone().unwrap_or_else(|| langid!("en-US"));
114+
let locale = requested_locale.clone().unwrap_or(fallback_locale);
111115
trace!(?locale);
112116
let mut bundle = FluentBundle::new(vec![locale]);
113117

@@ -118,7 +122,8 @@ pub fn fluent_bundle(
118122
// surrounding diagnostic messages are right-to-left, then these might be helpful).
119123
bundle.set_use_isolating(false);
120124

121-
if let Some(requested_locale) = requested_locale {
125+
// If the user requests the default locale then don't try to load anything.
126+
if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
122127
let mut sysroot = sysroot.to_path_buf();
123128
sysroot.push("share");
124129
sysroot.push("locale");
@@ -140,7 +145,8 @@ pub fn fluent_bundle(
140145
continue;
141146
}
142147

143-
let resource_str = fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
148+
let resource_str =
149+
fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
144150
let resource =
145151
FluentResource::try_new(resource_str).map_err(TranslationBundleError::from)?;
146152
trace!(?resource);

0 commit comments

Comments
 (0)