@@ -160,8 +160,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
160
160
161
161
pub fn sysroot_candidates ( ) -> SmallVec < [ PathBuf ; 2 ] > {
162
162
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( ) ] ;
165
164
let path = current_dll_path ( ) . and_then ( |s| try_canonicalize ( s) . map_err ( |e| e. to_string ( ) ) ) ;
166
165
if let Ok ( dll) = path {
167
166
// use `parent` twice to chop off the file name and then also the
@@ -195,12 +194,12 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
195
194
/// Returns the provided sysroot or calls [`get_or_default_sysroot`] if it's none.
196
195
/// Panics if [`get_or_default_sysroot`] returns an error.
197
196
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 ( ) )
199
198
}
200
199
201
200
/// This function checks if sysroot is found using env::args().next(), and if it
202
201
/// 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 {
204
203
// Follow symlinks. If the resolved path is relative, make it absolute.
205
204
fn canonicalize ( path : PathBuf ) -> PathBuf {
206
205
let path = try_canonicalize ( & path) . unwrap_or ( path) ;
@@ -255,30 +254,25 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
255
254
// binary able to locate Rust libraries in systems using content-addressable
256
255
// storage (CAS).
257
256
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 ;
280
266
}
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)
281
275
}
282
276
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" ) )
284
278
}
0 commit comments