Skip to content

Commit 2640da7

Browse files
committedDec 11, 2018
Remove Session::sysroot().
Instead of maybe storing its own sysroot and maybe deferring to the one in `Session::opts`, just clone the latter when necessary so one is always directly available. This removes the need for the getter.

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed
 

‎src/librustc/session/mod.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use std::cell::{self, Cell, RefCell};
4848
use std::env;
4949
use std::fmt;
5050
use std::io::Write;
51-
use std::path::{Path, PathBuf};
51+
use std::path::PathBuf;
5252
use std::time::Duration;
5353
use std::sync::mpsc;
5454
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -69,7 +69,7 @@ pub struct Session {
6969
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
7070
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
7171
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
72-
pub default_sysroot: Option<PathBuf>,
72+
pub sysroot: PathBuf,
7373
/// The name of the root source file of the crate, in the local file system.
7474
/// `None` means that there is no source file.
7575
pub local_crate_source_file: Option<PathBuf>,
@@ -694,25 +694,17 @@ impl Session {
694694
)
695695
}
696696

697-
pub fn sysroot<'a>(&'a self) -> &'a Path {
698-
match self.opts.maybe_sysroot {
699-
Some(ref sysroot) => sysroot,
700-
None => self.default_sysroot
701-
.as_ref()
702-
.expect("missing sysroot and default_sysroot in Session"),
703-
}
704-
}
705697
pub fn target_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
706698
filesearch::FileSearch::new(
707-
self.sysroot(),
699+
&self.sysroot,
708700
self.opts.target_triple.triple(),
709701
&self.opts.search_paths,
710702
kind,
711703
)
712704
}
713705
pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
714706
filesearch::FileSearch::new(
715-
self.sysroot(),
707+
&self.sysroot,
716708
config::host_triple(),
717709
&self.opts.search_paths,
718710
kind,
@@ -1109,9 +1101,9 @@ pub fn build_session_(
11091101
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
11101102

11111103
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, source_map);
1112-
let default_sysroot = match sopts.maybe_sysroot {
1113-
Some(_) => None,
1114-
None => Some(filesearch::get_or_default_sysroot()),
1104+
let sysroot = match &sopts.maybe_sysroot {
1105+
Some(sysroot) => sysroot.clone(),
1106+
None => filesearch::get_or_default_sysroot(),
11151107
};
11161108

11171109
let file_path_mapping = sopts.file_path_mapping();
@@ -1147,7 +1139,7 @@ pub fn build_session_(
11471139
entry_fn: Once::new(),
11481140
plugin_registrar_fn: Once::new(),
11491141
proc_macro_decls_static: Once::new(),
1150-
default_sysroot,
1142+
sysroot,
11511143
local_crate_source_file,
11521144
working_dir,
11531145
lint_store: RwLock::new(lint::LintStore::new()),

‎src/librustc_codegen_llvm/back/link.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1024,11 +1024,10 @@ fn link_args(cmd: &mut dyn Linker,
10241024
// where extern libraries might live, based on the
10251025
// addl_lib_search_paths
10261026
if sess.opts.cg.rpath {
1027-
let sysroot = sess.sysroot();
10281027
let target_triple = sess.opts.target_triple.triple();
10291028
let mut get_install_prefix_lib_path = || {
10301029
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
1031-
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
1030+
let tlib = filesearch::relative_target_lib_path(&sess.sysroot, target_triple);
10321031
let mut path = PathBuf::from(install_prefix);
10331032
path.push(&tlib);
10341033

‎src/librustc_codegen_ssa/back/linker.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ impl<'a> Linker for MsvcLinker<'a> {
606606
self.cmd.arg("/DEBUG");
607607

608608
// This will cause the Microsoft linker to embed .natvis info into the PDB file
609-
let sysroot = self.sess.sysroot();
610-
let natvis_dir_path = sysroot.join("lib\\rustlib\\etc");
609+
let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
611610
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
612611
// LLVM 5.0.0's lld-link frontend doesn't yet recognize, and chokes
613612
// on, the /NATVIS:... flags. LLVM 6 (or earlier) should at worst ignore

‎src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl RustcDefaultCalls {
10421042
targets.sort();
10431043
println!("{}", targets.join("\n"));
10441044
},
1045-
Sysroot => println!("{}", sess.sysroot().display()),
1045+
Sysroot => println!("{}", sess.sysroot.display()),
10461046
TargetSpec => println!("{}", sess.target.target.to_json().pretty()),
10471047
FileNames | CrateName => {
10481048
let input = input.unwrap_or_else(||

‎src/librustc_metadata/locator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl<'a> Context<'a> {
678678
// candidates are all canonicalized, so we canonicalize the sysroot
679679
// as well.
680680
if let Some((ref prev, _)) = ret {
681-
let sysroot = self.sess.sysroot();
681+
let sysroot = &self.sess.sysroot;
682682
let sysroot = sysroot.canonicalize()
683683
.unwrap_or_else(|_| sysroot.to_path_buf());
684684
if prev.starts_with(&sysroot) {

0 commit comments

Comments
 (0)
Please sign in to comment.