Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e8494f

Browse files
committed
Don't return an error from get_or_default_sysroot
All callers unwrap the result.
1 parent 0a67951 commit 7e8494f

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

‎compiler/rustc_codegen_ssa/src/back/link.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,7 @@ fn link_sanitizer_runtime(
12861286
if path.exists() {
12871287
sess.target_tlib_path.dir.clone()
12881288
} else {
1289-
let default_sysroot =
1290-
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
1289+
let default_sysroot = filesearch::get_or_default_sysroot();
12911290
let default_tlib =
12921291
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.tuple());
12931292
default_tlib

‎compiler/rustc_session/src/filesearch.rs‎

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
160160

161161
pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
162162
let target = crate::config::host_tuple();
163-
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
164-
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
163+
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> = smallvec![get_or_default_sysroot()];
165164
let path = current_dll_path().and_then(|s| try_canonicalize(s).map_err(|e| e.to_string()));
166165
if let Ok(dll) = path {
167166
// use `parent` twice to chop off the file name and then also the
@@ -195,12 +194,12 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
195194
/// Returns the provided sysroot or calls [`get_or_default_sysroot`] if it's none.
196195
/// Panics if [`get_or_default_sysroot`] returns an error.
197196
pub fn materialize_sysroot(maybe_sysroot: Option<PathBuf>) -> PathBuf {
198-
maybe_sysroot.unwrap_or_else(|| get_or_default_sysroot().expect("Failed finding sysroot"))
197+
maybe_sysroot.unwrap_or_else(|| get_or_default_sysroot())
199198
}
200199

201200
/// This function checks if sysroot is found using env::args().next(), and if it
202201
/// is not found, finds sysroot from current rustc_driver dll.
203-
pub fn get_or_default_sysroot() -> Result<PathBuf,String> {
202+
pub fn get_or_default_sysroot() -> PathBuf {
204203
// Follow symlinks. If the resolved path is relative, make it absolute.
205204
fn canonicalize(path: PathBuf) -> PathBuf {
206205
let path = try_canonicalize(&path).unwrap_or(path);
@@ -255,30 +254,25 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
255254
// binary able to locate Rust libraries in systems using content-addressable
256255
// storage (CAS).
257256
fn from_env_args_next() -> Option<PathBuf> {
258-
match env::args_os().next() {
259-
Some(first_arg) => {
260-
let mut p = PathBuf::from(first_arg);
261-
262-
// Check if sysroot is found using env::args().next() only if the rustc in argv[0]
263-
// is a symlink (see #79253). We might want to change/remove it to conform with
264-
// https://www.gnu.org/prep/standards/standards.html#Finding-Program-Files in the
265-
// future.
266-
if fs::read_link(&p).is_err() {
267-
// Path is not a symbolic link or does not exist.
268-
return None;
269-
}
270-
271-
// Pop off `bin/rustc`, obtaining the suspected sysroot.
272-
p.pop();
273-
p.pop();
274-
// Look for the target rustlib directory in the suspected sysroot.
275-
let mut rustlib_path = rustc_target::relative_target_rustlib_path(&p, "dummy");
276-
rustlib_path.pop(); // pop off the dummy target.
277-
rustlib_path.exists().then_some(p)
278-
}
279-
None => None,
257+
let mut p = PathBuf::from(env::args_os().next()?);
258+
259+
// Check if sysroot is found using env::args().next() only if the rustc in argv[0]
260+
// is a symlink (see #79253). We might want to change/remove it to conform with
261+
// https://www.gnu.org/prep/standards/standards.html#Finding-Program-Files in the
262+
// future.
263+
if fs::read_link(&p).is_err() {
264+
// Path is not a symbolic link or does not exist.
265+
return None;
280266
}
267+
268+
// Pop off `bin/rustc`, obtaining the suspected sysroot.
269+
p.pop();
270+
p.pop();
271+
// Look for the target rustlib directory in the suspected sysroot.
272+
let mut rustlib_path = rustc_target::relative_target_rustlib_path(&p, "dummy");
273+
rustlib_path.pop(); // pop off the dummy target.
274+
rustlib_path.exists().then_some(p)
281275
}
282276

283-
Ok(from_env_args_next().unwrap_or(default_from_rustc_driver_dll()?))
277+
from_env_args_next().unwrap_or(default_from_rustc_driver_dll().expect("Failed finding sysroot"))
284278
}

‎src/librustdoc/config.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,7 @@ impl Options {
734734

735735
let sysroot = match &maybe_sysroot {
736736
Some(s) => s.clone(),
737-
None => {
738-
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
739-
}
737+
None => rustc_session::filesearch::get_or_default_sysroot(),
740738
};
741739

742740
let libs = matches

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /