Skip to content
Merged
Prev Previous commit
Next Next commit
rustc_metadata: locator::Context -> CrateLocator
  • Loading branch information
petrochenkov committed Nov 17, 2019
commit c6bcf6016c0049033b11acccf4894da5c344bd54
34 changes: 17 additions & 17 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Validates all used crates and extern libraries and loads their metadata

use crate::cstore::{self, CStore};
use crate::locator::{self, CratePaths};
use crate::locator::{CrateLocator, CratePaths};
use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob};
use rustc_data_structures::sync::{Lock, Once, AtomicCell};

Expand Down Expand Up @@ -68,13 +68,13 @@ enum LoadResult {
}

enum LoadError<'a> {
LocatorError(locator::Context<'a>),
LocatorError(CrateLocator<'a>),
}

impl<'a> LoadError<'a> {
fn report(self) -> ! {
match self {
LoadError::LocatorError(locate_ctxt) => locate_ctxt.report_errs(),
LoadError::LocatorError(locator) => locator.report_errs(),
}
}
}
Expand Down Expand Up @@ -267,15 +267,15 @@ impl<'a> CrateLoader<'a> {

fn load_proc_macro<'b>(
&self,
locate_ctxt: &mut locator::Context<'b>,
locator: &mut CrateLocator<'b>,
path_kind: PathKind,
) -> Option<(LoadResult, Option<Library>)>
where
'a: 'b,
{
// Use a new locator Context so trying to load a proc macro doesn't affect the error
// Use a new crate locator so trying to load a proc macro doesn't affect the error
// message we emit
let mut proc_macro_locator = locate_ctxt.clone();
let mut proc_macro_locator = locator.clone();

// Try to load a proc macro
proc_macro_locator.is_proc_macro = Some(true);
Expand All @@ -287,10 +287,10 @@ impl<'a> CrateLoader<'a> {
LoadResult::Previous(cnum) => return Some((LoadResult::Previous(cnum), None)),
LoadResult::Loaded(library) => Some(LoadResult::Loaded(library))
};
locate_ctxt.hash = locate_ctxt.host_hash;
// Use the locate_ctxt when looking for the host proc macro crate, as that is required
locator.hash = locator.host_hash;
// Use the locator when looking for the host proc macro crate, as that is required
// so we want it to affect the error message
(locate_ctxt, result)
(locator, result)
} else {
(&mut proc_macro_locator, None)
};
Expand Down Expand Up @@ -350,7 +350,7 @@ impl<'a> CrateLoader<'a> {
(LoadResult::Previous(cnum), None)
} else {
info!("falling back to a load");
let mut locate_ctxt = locator::Context {
let mut locator = CrateLocator {
sess: self.sess,
span,
crate_name: name,
Expand All @@ -371,10 +371,10 @@ impl<'a> CrateLoader<'a> {
metadata_loader: self.metadata_loader,
};

self.load(&mut locate_ctxt).map(|r| (r, None)).or_else(|| {
self.load(&mut locator).map(|r| (r, None)).or_else(|| {
dep_kind = DepKind::UnexportedMacrosOnly;
self.load_proc_macro(&mut locate_ctxt, path_kind)
}).ok_or_else(move || LoadError::LocatorError(locate_ctxt))?
self.load_proc_macro(&mut locator, path_kind)
}).ok_or_else(move || LoadError::LocatorError(locator))?
};

match result {
Expand All @@ -395,8 +395,8 @@ impl<'a> CrateLoader<'a> {
}
}

fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
let library = locate_ctxt.maybe_load_library_crate()?;
fn load(&self, locator: &mut CrateLocator<'_>) -> Option<LoadResult> {
let library = locator.maybe_load_library_crate()?;

// In the case that we're loading a crate, but not matching
// against a hash, we could load a crate which has the same hash
Expand All @@ -407,11 +407,11 @@ impl<'a> CrateLoader<'a> {
// don't want to match a host crate against an equivalent target one
// already loaded.
let root = library.metadata.get_root();
if locate_ctxt.triple == self.sess.opts.target_triple {
if locator.triple == self.sess.opts.target_triple {
let mut result = LoadResult::Loaded(library);
self.cstore.iter_crate_data(|cnum, data| {
if data.root.name == root.name && root.hash == data.root.hash {
assert!(locate_ctxt.hash.is_none());
assert!(locator.hash.is_none());
info!("load success, going to previous cnum: {}", cnum);
result = LoadResult::Previous(cnum);
}
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ crate struct CrateMismatch {
}

#[derive(Clone)]
crate struct Context<'a> {
crate struct CrateLocator<'a> {
pub sess: &'a Session,
pub span: Span,
pub crate_name: Symbol,
Expand Down Expand Up @@ -298,7 +298,7 @@ impl fmt::Display for CrateFlavor {
}
}

impl<'a> Context<'a> {
impl<'a> CrateLocator<'a> {
crate fn reset(&mut self) {
self.rejected_via_hash.clear();
self.rejected_via_triple.clear();
Expand Down Expand Up @@ -926,7 +926,7 @@ pub fn find_plugin_registrar(
let host_triple = TargetTriple::from_triple(config::host_triple());
let is_cross = target_triple != host_triple;
let mut target_only = false;
let mut locate_ctxt = Context {
let mut locator = CrateLocator {
sess,
span,
crate_name: name,
Expand All @@ -947,23 +947,23 @@ pub fn find_plugin_registrar(
metadata_loader,
};

let library = locate_ctxt.maybe_load_library_crate().or_else(|| {
let library = locator.maybe_load_library_crate().or_else(|| {
if !is_cross {
return None
}
// Try loading from target crates. This will abort later if we
// try to load a plugin registrar function,
target_only = true;

locate_ctxt.target = &sess.target.target;
locate_ctxt.triple = target_triple;
locate_ctxt.filesearch = sess.target_filesearch(PathKind::Crate);
locator.target = &sess.target.target;
locator.triple = target_triple;
locator.filesearch = sess.target_filesearch(PathKind::Crate);

locate_ctxt.maybe_load_library_crate()
locator.maybe_load_library_crate()
});
let library = match library {
Some(l) => l,
None => locate_ctxt.report_errs(),
None => locator.report_errs(),
};

if target_only {
Expand Down