Make most CrateLocator fields private

This ensures they don't get out of sync
This commit is contained in:
bjorn3 2024-03-23 16:37:07 +00:00
parent 57d6c1bab8
commit 47caa0a927
2 changed files with 29 additions and 27 deletions

View file

@ -24,8 +24,7 @@ use rustc_middle::ty::data_structures::IndexSet;
use rustc_middle::ty::{TyCtxt, TyCtxtFeed};
use rustc_proc_macro::bridge::client::ProcMacro;
use rustc_session::config::{
self, CrateType, ExtendedTargetModifierInfo, ExternLocation, OptionsTargetModifiers,
TargetModifier,
CrateType, ExtendedTargetModifierInfo, ExternLocation, OptionsTargetModifiers, TargetModifier,
};
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
use rustc_session::lint::{self, BuiltinLintDiag};
@ -33,7 +32,7 @@ use rustc_session::output::validate_crate_name;
use rustc_session::search_paths::PathKind;
use rustc_span::edition::Edition;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
use rustc_target::spec::{PanicStrategy, Target, TargetTuple};
use rustc_target::spec::{PanicStrategy, Target};
use tracing::{debug, info, trace};
use crate::errors;
@ -697,7 +696,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
let mut proc_macro_locator = locator.clone();
// Try to load a proc macro
proc_macro_locator.is_proc_macro = true;
proc_macro_locator.for_target_proc_macro(self.sess, path_kind);
// Load the proc macro crate for the target
let target_result =
@ -709,17 +708,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
None => return Ok(None),
};
// Load the proc macro crate for the host
// Use the existing crate_rejections as we want the error message to be affected by
// loading the host proc macro.
*crate_rejections = CrateRejections::default();
// FIXME use a separate CrateLocator for the host rather than mutating the target CrateLocator
locator.is_proc_macro = true;
locator.target = &self.sess.host;
locator.tuple = TargetTuple::from_tuple(config::host_tuple());
locator.filesearch = self.sess.host_filesearch();
locator.path_kind = path_kind;
// Load the proc macro crate for the host
locator.for_proc_macro(self.sess, path_kind);
locator.hash = host_hash;
@ -739,16 +733,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// affect the error message we emit
let mut proc_macro_locator = locator.clone();
// Try to load a proc macro
proc_macro_locator.is_proc_macro = true;
// Load the proc macro crate for the host
// FIXME use a separate CrateLocator for the host rather than mutating the target CrateLocator
proc_macro_locator.target = &self.sess.host;
proc_macro_locator.tuple = TargetTuple::from_tuple(config::host_tuple());
proc_macro_locator.filesearch = self.sess.host_filesearch();
proc_macro_locator.path_kind = path_kind;
proc_macro_locator.for_proc_macro(self.sess, path_kind);
let Some(host_result) =
self.load(&mut proc_macro_locator, &mut CrateRejections::default())?

View file

@ -224,11 +224,11 @@ use rustc_data_structures::owned_slice::{OwnedSlice, slice_owned};
use rustc_data_structures::svh::Svh;
use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_fs_util::try_canonicalize;
use rustc_session::Session;
use rustc_session::cstore::CrateSource;
use rustc_session::filesearch::FileSearch;
use rustc_session::search_paths::PathKind;
use rustc_session::utils::CanonicalizedPath;
use rustc_session::{Session, config};
use rustc_span::{Span, Symbol};
use rustc_target::spec::{Target, TargetTuple};
use tempfile::Builder as TempFileBuilder;
@ -251,11 +251,11 @@ pub(crate) struct CrateLocator<'a> {
exact_paths: Vec<CanonicalizedPath>,
pub hash: Option<Svh>,
extra_filename: Option<&'a str>,
pub target: &'a Target,
pub tuple: TargetTuple,
pub filesearch: &'a FileSearch,
pub is_proc_macro: bool,
pub path_kind: PathKind,
target: &'a Target,
tuple: TargetTuple,
filesearch: &'a FileSearch,
is_proc_macro: bool,
path_kind: PathKind,
}
#[derive(Clone, Debug)]
@ -346,6 +346,22 @@ impl<'a> CrateLocator<'a> {
}
}
pub(crate) fn for_proc_macro(&mut self, sess: &'a Session, path_kind: PathKind) {
self.is_proc_macro = true;
self.target = &sess.host;
self.tuple = TargetTuple::from_tuple(config::host_tuple());
self.filesearch = sess.host_filesearch();
self.path_kind = path_kind;
}
pub(crate) fn for_target_proc_macro(&mut self, sess: &'a Session, path_kind: PathKind) {
self.is_proc_macro = true;
self.target = &sess.target;
self.tuple = sess.opts.target_triple.clone();
self.filesearch = sess.target_filesearch();
self.path_kind = path_kind;
}
pub(crate) fn maybe_load_library_crate(
&self,
crate_rejections: &mut CrateRejections,