about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-04-02 06:09:43 +0100
committerDavid Wood <david.wood@huawei.com>2022-04-05 07:01:03 +0100
commit141f8404a8dc2a6c00aafc917c11071275ee82ef (patch)
tree3ffb645cc033e689ad43d3d6689726056fdb80ac /compiler
parent22685b9607936ae1330e2f84773c04292f5cdd30 (diff)
downloadrust-141f8404a8dc2a6c00aafc917c11071275ee82ef.tar.gz
rust-141f8404a8dc2a6c00aafc917c11071275ee82ef.zip
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 <david.wood@huawei.com>
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_error_messages/src/lib.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index c5fd43eda3c..4a83a84a83d 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -1,3 +1,4 @@
+#![feature(let_chains)]
 #![feature(path_try_exists)]
 
 use fluent_bundle::FluentResource;
@@ -105,9 +106,12 @@ pub fn fluent_bundle(
         return Ok(None);
     }
 
+    let fallback_locale = langid!("en-US");
+    let requested_fallback_locale = requested_locale.as_ref() == Some(&fallback_locale);
+
     // If there is only `-Z additional-ftl-path`, assume locale is "en-US", otherwise use user
     // provided locale.
-    let locale = requested_locale.clone().unwrap_or_else(|| langid!("en-US"));
+    let locale = requested_locale.clone().unwrap_or(fallback_locale);
     trace!(?locale);
     let mut bundle = FluentBundle::new(vec![locale]);
 
@@ -118,7 +122,8 @@ pub fn fluent_bundle(
     // surrounding diagnostic messages are right-to-left, then these might be helpful).
     bundle.set_use_isolating(false);
 
-    if let Some(requested_locale) = requested_locale {
+    // If the user requests the default locale then don't try to load anything.
+    if !requested_fallback_locale && let Some(requested_locale) = requested_locale {
         let mut sysroot = sysroot.to_path_buf();
         sysroot.push("share");
         sysroot.push("locale");
@@ -140,7 +145,8 @@ pub fn fluent_bundle(
                 continue;
             }
 
-            let resource_str = fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
+            let resource_str =
+                fs::read_to_string(path).map_err(TranslationBundleError::ReadFtl)?;
             let resource =
                 FluentResource::try_new(resource_str).map_err(TranslationBundleError::from)?;
             trace!(?resource);