diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2024-03-23 16:37:07 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-07-03 11:57:56 +0000 |
| commit | 47caa0a92744b3dd0b525596ebd0d5fe71089f1e (patch) | |
| tree | ef2541d863a54a3fb1d8c33db9ce95c26a65ba97 | |
| parent | 57d6c1bab882d21a104e3db8f5a0cfc80c2e91d3 (diff) | |
| download | rust-47caa0a92744b3dd0b525596ebd0d5fe71089f1e.tar.gz rust-47caa0a92744b3dd0b525596ebd0d5fe71089f1e.zip | |
Make most CrateLocator fields private
This ensures they don't get out of sync
| -rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/locator.rs | 28 |
2 files changed, 29 insertions, 27 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 4e3921e83de..e65c7a68426 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -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())? diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 2578526e468..36ce93737e8 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -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, |
