rustc_session: Add a structure for keeping both explicit and default sysroots

Also avoid creating and cloning sysroot unnecessarily.
This commit is contained in:
Vadim Petrochenkov
2025-06-20 18:52:13 +03:00
parent e4b9d0141f
commit 0be37cab97
18 changed files with 93 additions and 97 deletions

View File

@@ -8,7 +8,7 @@
use std::borrow::Cow;
use std::error::Error;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::sync::{Arc, LazyLock};
use std::{fmt, fs, io};
@@ -21,7 +21,6 @@ use intl_memoizer::concurrent::IntlLangMemoizer;
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend};
use rustc_macros::{Decodable, Encodable};
use rustc_span::Span;
use smallvec::SmallVec;
use tracing::{instrument, trace};
pub use unic_langid::{LanguageIdentifier, langid};
@@ -107,7 +106,7 @@ impl From<Vec<FluentError>> for TranslationBundleError {
/// (overriding any conflicting messages).
#[instrument(level = "trace")]
pub fn fluent_bundle(
sysroot_candidates: SmallVec<[PathBuf; 2]>,
sysroot_candidates: &[&Path],
requested_locale: Option<LanguageIdentifier>,
additional_ftl_path: Option<&Path>,
with_directionality_markers: bool,
@@ -141,7 +140,8 @@ pub fn fluent_bundle(
// If the user requests the default locale then don't try to load anything.
if let Some(requested_locale) = requested_locale {
let mut found_resources = false;
for mut sysroot in sysroot_candidates {
for sysroot in sysroot_candidates {
let mut sysroot = sysroot.to_path_buf();
sysroot.push("share");
sysroot.push("locale");
sysroot.push(requested_locale.to_string());