@@ -240,7 +240,8 @@ use tracing::{debug, info, warn};
240
240
#[ derive( Clone ) ]
241
241
crate struct CrateLocator < ' a > {
242
242
// Immutable per-session configuration.
243
- sess : & ' a Session ,
243
+ only_needs_metadata : bool ,
244
+ sysroot : & ' a Path ,
244
245
metadata_loader : & ' a dyn MetadataLoader ,
245
246
246
247
// Immutable per-search configuration.
@@ -305,8 +306,18 @@ impl<'a> CrateLocator<'a> {
305
306
root : Option < & ' a CratePaths > ,
306
307
is_proc_macro : Option < bool > ,
307
308
) -> CrateLocator < ' a > {
309
+ // The all loop is because `--crate-type=rlib --crate-type=rlib` is
310
+ // legal and produces both inside this type.
311
+ let is_rlib = sess. crate_types ( ) . iter ( ) . all ( |c| * c == CrateType :: Rlib ) ;
312
+ let needs_object_code = sess. opts . output_types . should_codegen ( ) ;
313
+ // If we're producing an rlib, then we don't need object code.
314
+ // Or, if we're not producing object code, then we don't need it either
315
+ // (e.g., if we're a cdylib but emitting just metadata).
316
+ let only_needs_metadata = is_rlib || !needs_object_code;
317
+
308
318
CrateLocator {
309
- sess,
319
+ only_needs_metadata,
320
+ sysroot : & sess. sysroot ,
310
321
metadata_loader,
311
322
crate_name,
312
323
exact_paths : if hash. is_none ( ) {
@@ -484,14 +495,7 @@ impl<'a> CrateLocator<'a> {
484
495
return true ;
485
496
}
486
497
487
- // The all loop is because `--crate-type=rlib --crate-type=rlib` is
488
- // legal and produces both inside this type.
489
- let is_rlib = self . sess . crate_types ( ) . iter ( ) . all ( |c| * c == CrateType :: Rlib ) ;
490
- let needs_object_code = self . sess . opts . output_types . should_codegen ( ) ;
491
- // If we're producing an rlib, then we don't need object code.
492
- // Or, if we're not producing object code, then we don't need it either
493
- // (e.g., if we're a cdylib but emitting just metadata).
494
- if is_rlib || !needs_object_code {
498
+ if self . only_needs_metadata {
495
499
flavor == CrateFlavor :: Rmeta
496
500
} else {
497
501
// we need all flavors (perhaps not true, but what we do for now)
@@ -591,7 +595,7 @@ impl<'a> CrateLocator<'a> {
591
595
// candidates are all canonicalized, so we canonicalize the sysroot
592
596
// as well.
593
597
if let Some ( ( prev, _) ) = & ret {
594
- let sysroot = & self . sess . sysroot ;
598
+ let sysroot = self . sysroot ;
595
599
let sysroot = sysroot. canonicalize ( ) . unwrap_or_else ( |_| sysroot. to_path_buf ( ) ) ;
596
600
if prev. starts_with ( & sysroot) {
597
601
continue ;
0 commit comments