Skip to content

Commit e4c4c4c

Browse files
committed
Fix review comments
1 parent dff8ee5 commit e4c4c4c

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,7 @@ dependencies = [
36403640
"rustc_macros",
36413641
"rustc_serialize",
36423642
"rustc_span",
3643+
"smallvec",
36433644
"tracing",
36443645
"unic-langid",
36453646
]

compiler/rustc_error_messages/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1616
rustc_macros = { path = "../rustc_macros" }
1717
rustc_serialize = { path = "../rustc_serialize" }
1818
rustc_span = { path = "../rustc_span" }
19+
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1920
tracing = "0.1"
2021
unic-langid = { version = "0.9.0", features = ["macros"] }
2122
# tidy-alphabetical-end

compiler/rustc_error_messages/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use intl_memoizer::concurrent::IntlLangMemoizer;
2121
use rustc_data_structures::sync::IntoDynSyncSend;
2222
use rustc_macros::{Decodable, Encodable};
2323
use rustc_span::Span;
24+
use smallvec::SmallVec;
2425
use tracing::{instrument, trace};
2526
pub use unic_langid::{LanguageIdentifier, langid};
2627

@@ -106,8 +107,7 @@ impl From<Vec<FluentError>> for TranslationBundleError {
106107
/// (overriding any conflicting messages).
107108
#[instrument(level = "trace")]
108109
pub fn fluent_bundle(
109-
sysroot: PathBuf,
110-
default_sysroot: PathBuf,
110+
sysroot_candidates: SmallVec<[PathBuf; 2]>,
111111
requested_locale: Option<LanguageIdentifier>,
112112
additional_ftl_path: Option<&Path>,
113113
with_directionality_markers: bool,
@@ -141,7 +141,7 @@ pub fn fluent_bundle(
141141
// If the user requests the default locale then don't try to load anything.
142142
if let Some(requested_locale) = requested_locale {
143143
let mut found_resources = false;
144-
for mut sysroot in [sysroot, default_sysroot] {
144+
for mut sysroot in sysroot_candidates {
145145
sysroot.push("share");
146146
sysroot.push("locale");
147147
sysroot.push(requested_locale.to_string());

compiler/rustc_interface/src/interface.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_parse::parser::attr::AllowLeadingUnsafe;
1818
use rustc_query_impl::QueryCtxt;
1919
use rustc_query_system::query::print_query_stack;
2020
use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName};
21-
use rustc_session::filesearch::get_or_default_sysroot;
21+
use rustc_session::filesearch::sysroot_with_fallback;
2222
use rustc_session::parse::ParseSess;
2323
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint};
2424
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMapInputs};
@@ -442,8 +442,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
442442
let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
443443

444444
let bundle = match rustc_errors::fluent_bundle(
445-
config.opts.sysroot.clone(),
446-
get_or_default_sysroot(),
445+
sysroot_with_fallback(&config.opts.sysroot),
447446
config.opts.unstable_opts.translate_lang.clone(),
448447
config.opts.unstable_opts.translate_additional_ftl.as_deref(),
449448
config.opts.unstable_opts.translate_directionality_markers,

compiler/rustc_interface/src/util.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,10 @@ pub fn rustc_path<'a>() -> Option<&'a Path> {
345345
}
346346

347347
fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
348-
Some(filesearch::get_or_default_sysroot()).iter().find_map(|sysroot| {
349-
let candidate = sysroot.join(bin_path).join(if cfg!(target_os = "windows") {
350-
"rustc.exe"
351-
} else {
352-
"rustc"
353-
});
354-
candidate.exists().then_some(candidate)
355-
})
348+
let candidate = filesearch::get_or_default_sysroot()
349+
.join(bin_path)
350+
.join(if cfg!(target_os = "windows") { "rustc.exe" } else { "rustc" });
351+
candidate.exists().then_some(candidate)
356352
}
357353

358354
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable

0 commit comments

Comments
 (0)