Skip to content

Commit 47caa0a

Browse files
committed
Make most CrateLocator fields private
This ensures they don't get out of sync
1 parent 57d6c1b commit 47caa0a

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ use rustc_middle::ty::data_structures::IndexSet;
2424
use rustc_middle::ty::{TyCtxt, TyCtxtFeed};
2525
use rustc_proc_macro::bridge::client::ProcMacro;
2626
use rustc_session::config::{
27-
self, CrateType, ExtendedTargetModifierInfo, ExternLocation, OptionsTargetModifiers,
28-
TargetModifier,
27+
CrateType, ExtendedTargetModifierInfo, ExternLocation, OptionsTargetModifiers, TargetModifier,
2928
};
3029
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
3130
use rustc_session::lint::{self, BuiltinLintDiag};
3231
use rustc_session::output::validate_crate_name;
3332
use rustc_session::search_paths::PathKind;
3433
use rustc_span::edition::Edition;
3534
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
36-
use rustc_target::spec::{PanicStrategy, Target, TargetTuple};
35+
use rustc_target::spec::{PanicStrategy, Target};
3736
use tracing::{debug, info, trace};
3837

3938
use crate::errors;
@@ -697,7 +696,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
697696
let mut proc_macro_locator = locator.clone();
698697

699698
// Try to load a proc macro
700-
proc_macro_locator.is_proc_macro = true;
699+
proc_macro_locator.for_target_proc_macro(self.sess, path_kind);
701700

702701
// Load the proc macro crate for the target
703702
let target_result =
@@ -709,17 +708,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
709708
None => return Ok(None),
710709
};
711710

712-
// Load the proc macro crate for the host
713-
714711
// Use the existing crate_rejections as we want the error message to be affected by
715712
// loading the host proc macro.
716713
*crate_rejections = CrateRejections::default();
717-
// FIXME use a separate CrateLocator for the host rather than mutating the target CrateLocator
718-
locator.is_proc_macro = true;
719-
locator.target = &self.sess.host;
720-
locator.tuple = TargetTuple::from_tuple(config::host_tuple());
721-
locator.filesearch = self.sess.host_filesearch();
722-
locator.path_kind = path_kind;
714+
715+
// Load the proc macro crate for the host
716+
locator.for_proc_macro(self.sess, path_kind);
723717

724718
locator.hash = host_hash;
725719

@@ -739,16 +733,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
739733
// affect the error message we emit
740734
let mut proc_macro_locator = locator.clone();
741735

742-
// Try to load a proc macro
743-
proc_macro_locator.is_proc_macro = true;
744-
745736
// Load the proc macro crate for the host
746-
747-
// FIXME use a separate CrateLocator for the host rather than mutating the target CrateLocator
748-
proc_macro_locator.target = &self.sess.host;
749-
proc_macro_locator.tuple = TargetTuple::from_tuple(config::host_tuple());
750-
proc_macro_locator.filesearch = self.sess.host_filesearch();
751-
proc_macro_locator.path_kind = path_kind;
737+
proc_macro_locator.for_proc_macro(self.sess, path_kind);
752738

753739
let Some(host_result) =
754740
self.load(&mut proc_macro_locator, &mut CrateRejections::default())?

compiler/rustc_metadata/src/locator.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ use rustc_data_structures::owned_slice::{OwnedSlice, slice_owned};
224224
use rustc_data_structures::svh::Svh;
225225
use rustc_errors::{DiagArgValue, IntoDiagArg};
226226
use rustc_fs_util::try_canonicalize;
227-
use rustc_session::Session;
228227
use rustc_session::cstore::CrateSource;
229228
use rustc_session::filesearch::FileSearch;
230229
use rustc_session::search_paths::PathKind;
231230
use rustc_session::utils::CanonicalizedPath;
231+
use rustc_session::{Session, config};
232232
use rustc_span::{Span, Symbol};
233233
use rustc_target::spec::{Target, TargetTuple};
234234
use tempfile::Builder as TempFileBuilder;
@@ -251,11 +251,11 @@ pub(crate) struct CrateLocator<'a> {
251251
exact_paths: Vec<CanonicalizedPath>,
252252
pub hash: Option<Svh>,
253253
extra_filename: Option<&'a str>,
254-
pub target: &'a Target,
255-
pub tuple: TargetTuple,
256-
pub filesearch: &'a FileSearch,
257-
pub is_proc_macro: bool,
258-
pub path_kind: PathKind,
254+
target: &'a Target,
255+
tuple: TargetTuple,
256+
filesearch: &'a FileSearch,
257+
is_proc_macro: bool,
258+
path_kind: PathKind,
259259
}
260260

261261
#[derive(Clone, Debug)]
@@ -346,6 +346,22 @@ impl<'a> CrateLocator<'a> {
346346
}
347347
}
348348

349+
pub(crate) fn for_proc_macro(&mut self, sess: &'a Session, path_kind: PathKind) {
350+
self.is_proc_macro = true;
351+
self.target = &sess.host;
352+
self.tuple = TargetTuple::from_tuple(config::host_tuple());
353+
self.filesearch = sess.host_filesearch();
354+
self.path_kind = path_kind;
355+
}
356+
357+
pub(crate) fn for_target_proc_macro(&mut self, sess: &'a Session, path_kind: PathKind) {
358+
self.is_proc_macro = true;
359+
self.target = &sess.target;
360+
self.tuple = sess.opts.target_triple.clone();
361+
self.filesearch = sess.target_filesearch();
362+
self.path_kind = path_kind;
363+
}
364+
349365
pub(crate) fn maybe_load_library_crate(
350366
&self,
351367
crate_rejections: &mut CrateRejections,

0 commit comments

Comments
 (0)