Skip to content

Commit b54398e

Browse files
committed
Make opts.maybe_sysroot non-optional
build_session_options always uses materialize_sysroot anyway.
1 parent 57a4736 commit b54398e

9 files changed

Lines changed: 20 additions & 14 deletions

File tree

‎compiler/rustc_error_messages/src/lib.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl From<Vec<FluentError>> for TranslationBundleError {
107107
/// (overriding any conflicting messages).
108108
#[instrument(level = "trace")]
109109
pubfnfluent_bundle(
110-
mutuser_provided_sysroot:Option<PathBuf>,
110+
mutuser_provided_sysroot:PathBuf,
111111
mutsysroot_candidates:Vec<PathBuf>,
112112
requested_locale:Option<LanguageIdentifier>,
113113
additional_ftl_path:Option<&Path>,
@@ -142,7 +142,9 @@ pub fn fluent_bundle(
142142
// If the user requests the default locale then don't try to load anything.
143143
ifletSome(requested_locale) = requested_locale {
144144
letmut found_resources = false;
145-
for sysroot in user_provided_sysroot.iter_mut().chain(sysroot_candidates.iter_mut()){
145+
for sysroot in
146+
Some(&mut user_provided_sysroot).into_iter().chain(sysroot_candidates.iter_mut())
147+
{
146148
sysroot.push("share");
147149
sysroot.push("locale");
148150
sysroot.push(requested_locale.to_string());

‎compiler/rustc_interface/src/interface.rs‎

Lines changed: 3 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::{self,sysroot_candidates};
21+
use rustc_session::filesearch::sysroot_candidates;
2222
use rustc_session::parse::ParseSess;
2323
use rustc_session::{CompilerIO,EarlyDiagCtxt,Session, lint};
2424
use rustc_span::source_map::{FileLoader,RealFileLoader,SourceMapInputs};
@@ -390,7 +390,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
390390

391391
crate::callbacks::setup_callbacks();
392392

393-
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
393+
let sysroot = config.opts.sysroot.clone();
394394
let target = config::build_target_config(&early_dcx,&config.opts.target_triple,&sysroot);
395395
let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
396396
let path_mapping = config.opts.file_path_mapping();
@@ -424,7 +424,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
424424
let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
425425

426426
let bundle = match rustc_errors::fluent_bundle(
427-
config.opts.maybe_sysroot.clone(),
427+
config.opts.sysroot.clone(),
428428
sysroot_candidates().to_vec(),
429429
config.opts.unstable_opts.translate_lang.clone(),
430430
config.opts.unstable_opts.translate_additional_ftl.as_deref(),

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_session::config::{
2121
use rustc_session::lint::Level;
2222
use rustc_session::search_paths::SearchPath;
2323
use rustc_session::utils::{CanonicalizedPath,NativeLib,NativeLibKind};
24-
use rustc_session::{CompilerIO,EarlyDiagCtxt,Session, build_session,filesearch,getopts};
24+
use rustc_session::{CompilerIO,EarlyDiagCtxt,Session, build_session, getopts};
2525
use rustc_span::edition::{DEFAULT_EDITION,Edition};
2626
use rustc_span::source_map::{RealFileLoader,SourceMapInputs};
2727
use rustc_span::{FileName,SourceFileHashAlgorithm, sym};
@@ -41,7 +41,7 @@ where
4141

4242
let matches = optgroups().parse(args).unwrap();
4343
let sessopts = build_session_options(&mut early_dcx,&matches);
44-
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
44+
let sysroot = sessopts.sysroot.clone();
4545
let target =
4646
rustc_session::config::build_target_config(&early_dcx,&sessopts.target_triple,&sysroot);
4747
let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target);

‎compiler/rustc_session/src/config.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ impl Default for Options {
12141214
describe_lints:false,
12151215
output_types:OutputTypes(BTreeMap::new()),
12161216
search_paths:vec![],
1217-
maybe_sysroot:None,
1217+
sysroot: filesearch::materialize_sysroot(None),
12181218
target_triple:TargetTuple::from_tuple(host_tuple()),
12191219
test:false,
12201220
incremental:None,
@@ -2618,7 +2618,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26182618
describe_lints,
26192619
output_types,
26202620
search_paths,
2621-
maybe_sysroot:Some(sysroot),
2621+
sysroot,
26222622
target_triple,
26232623
test,
26242624
incremental,

‎compiler/rustc_session/src/options.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ top_level_options!(
333333
output_types:OutputTypes[TRACKED],
334334
search_paths:Vec<SearchPath> [UNTRACKED],
335335
libs:Vec<NativeLib> [TRACKED],
336-
maybe_sysroot:Option<PathBuf>[UNTRACKED],
336+
sysroot:PathBuf[UNTRACKED],
337337

338338
target_triple:TargetTuple[TRACKED],
339339

‎src/librustdoc/config.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ pub(crate) struct Options {
103103
/// compiling doctests from the crate.
104104
pub(crate)edition:Edition,
105105
/// The path to the sysroot. Used during the compilation process.
106+
pub(crate)sysroot:PathBuf,
107+
/// Has the same value as `sysroot` except is `None` when the user didn't pass `---sysroot`.
106108
pub(crate)maybe_sysroot:Option<PathBuf>,
107109
/// Lint information passed over the command-line.
108110
pub(crate)lint_opts:Vec<(String,Level)>,
@@ -202,6 +204,7 @@ impl fmt::Debug for Options {
202204
.field("unstable_options",&"...")
203205
.field("target",&self.target)
204206
.field("edition",&self.edition)
207+
.field("sysroot",&self.sysroot)
205208
.field("maybe_sysroot",&self.maybe_sysroot)
206209
.field("lint_opts",&self.lint_opts)
207210
.field("describe_lints",&self.describe_lints)
@@ -834,6 +837,7 @@ impl Options {
834837
unstable_opts_strs,
835838
target,
836839
edition,
840+
sysroot,
837841
maybe_sysroot,
838842
lint_opts,
839843
describe_lints,

‎src/librustdoc/core.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub(crate) fn create_config(
210210
unstable_opts,
211211
target,
212212
edition,
213-
maybe_sysroot,
213+
sysroot,
214214
lint_opts,
215215
describe_lints,
216216
lint_cap,
@@ -253,7 +253,7 @@ pub(crate) fn create_config(
253253
let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false);
254254
// plays with error output here!
255255
let sessopts = config::Options{
256-
maybe_sysroot,
256+
sysroot,
257257
search_paths: libs,
258258
crate_types,
259259
lint_opts,

‎src/librustdoc/doctest.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
158158
if options.proc_macro_crate{vec![CrateType::ProcMacro]}else{vec![CrateType::Rlib]};
159159

160160
let sessopts = config::Options{
161-
maybe_sysroot: options.maybe_sysroot.clone(),
161+
sysroot: options.sysroot.clone(),
162162
search_paths: options.libs.clone(),
163163
crate_types,
164164
lint_opts,

‎tests/ui-fulldeps/run-compiler-twice.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() {
4646
fncompile(code:String,output:PathBuf,sysroot:PathBuf,linker:Option<&Path>){
4747
letmut opts = Options::default();
4848
opts.output_types = OutputTypes::new(&[(OutputType::Exe,None)]);
49-
opts.maybe_sysroot = Some(sysroot);
49+
opts.sysroot = sysroot;
5050

5151
ifletSome(linker) = linker {
5252
opts.cg.linker = Some(linker.to_owned());

0 commit comments

Comments
 (0)