Skip to content

Commit 4f35f66

Browse files
committed
Don't store Session in CrateLocator
1 parent dbb0fe9 commit 4f35f66

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

compiler/rustc_metadata/src/locator.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ use tracing::{debug, info, warn};
240240
#[derive(Clone)]
241241
crate struct CrateLocator<'a> {
242242
// Immutable per-session configuration.
243-
sess: &'a Session,
243+
only_needs_metadata: bool,
244+
sysroot: &'a Path,
244245
metadata_loader: &'a dyn MetadataLoader,
245246

246247
// Immutable per-search configuration.
@@ -305,8 +306,18 @@ impl<'a> CrateLocator<'a> {
305306
root: Option<&'a CratePaths>,
306307
is_proc_macro: Option<bool>,
307308
) -> 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+
308318
CrateLocator {
309-
sess,
319+
only_needs_metadata,
320+
sysroot: &sess.sysroot,
310321
metadata_loader,
311322
crate_name,
312323
exact_paths: if hash.is_none() {
@@ -484,14 +495,7 @@ impl<'a> CrateLocator<'a> {
484495
return true;
485496
}
486497

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 {
495499
flavor == CrateFlavor::Rmeta
496500
} else {
497501
// we need all flavors (perhaps not true, but what we do for now)
@@ -591,7 +595,7 @@ impl<'a> CrateLocator<'a> {
591595
// candidates are all canonicalized, so we canonicalize the sysroot
592596
// as well.
593597
if let Some((prev, _)) = &ret {
594-
let sysroot = &self.sess.sysroot;
598+
let sysroot = self.sysroot;
595599
let sysroot = sysroot.canonicalize().unwrap_or_else(|_| sysroot.to_path_buf());
596600
if prev.starts_with(&sysroot) {
597601
continue;

0 commit comments

Comments
 (0)