Skip to content

Commit 5276987

Browse files
committed
rustc_metadata: Rename root to dep_root
Currently `root` or `crate_root` is used to refer to an instance of `CrateRoot` (representation of a crate's serialized metadata), but the name `root` sometimes also refers to a `CratePath` representing a "root" node in the dependency graph. In order to disambiguate, rename all instances of the latter to `dep_root`.
1 parent 90a8ea8 commit 5276987

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

compiler/rustc_metadata/src/creader.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
402402
fn register_crate(
403403
&mut self,
404404
host_lib: Option<Library>,
405-
root: Option<&CratePaths>,
405+
dep_root: Option<&CratePaths>,
406406
lib: Library,
407407
dep_kind: CrateDepKind,
408408
name: Symbol,
@@ -430,14 +430,14 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
430430
// Maintain a reference to the top most crate.
431431
// Stash paths for top-most crate locally if necessary.
432432
let crate_paths;
433-
let root = if let Some(root) = root {
434-
root
433+
let dep_root = if let Some(dep_root) = dep_root {
434+
dep_root
435435
} else {
436436
crate_paths = CratePaths::new(crate_root.name(), source.clone());
437437
&crate_paths
438438
};
439439

440-
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, dep_kind)?;
440+
let cnum_map = self.resolve_crate_deps(dep_root, &crate_root, &metadata, cnum, dep_kind)?;
441441

442442
let raw_proc_macros = if crate_root.is_proc_macro_crate() {
443443
let temp_root;
@@ -559,15 +559,15 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
559559
&'b mut self,
560560
name: Symbol,
561561
mut dep_kind: CrateDepKind,
562-
dep: Option<(&'b CratePaths, &'b CrateDep)>,
562+
dep_of: Option<(&'b CratePaths, &'b CrateDep)>,
563563
) -> Result<CrateNum, CrateError> {
564564
info!("resolving crate `{}`", name);
565565
if !name.as_str().is_ascii() {
566566
return Err(CrateError::NonAsciiName(name));
567567
}
568-
let (root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep {
569-
Some((root, dep)) => (
570-
Some(root),
568+
let (dep_root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep_of {
569+
Some((dep_root, dep)) => (
570+
Some(dep_root),
571571
Some(dep.hash),
572572
dep.host_hash,
573573
Some(&dep.extra_filename[..]),
@@ -599,7 +599,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
599599
dep_kind = CrateDepKind::MacrosOnly;
600600
match self.load_proc_macro(&mut locator, path_kind, host_hash)? {
601601
Some(res) => res,
602-
None => return Err(locator.into_error(root.cloned())),
602+
None => return Err(locator.into_error(dep_root.cloned())),
603603
}
604604
}
605605
}
@@ -623,7 +623,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
623623
}
624624
(LoadResult::Loaded(library), host_library) => {
625625
info!("register newly loaded library for `{}`", name);
626-
self.register_crate(host_library, root, library, dep_kind, name, private_dep)
626+
self.register_crate(host_library, dep_root, library, dep_kind, name, private_dep)
627627
}
628628
_ => panic!(),
629629
}
@@ -663,16 +663,20 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
663663
}))
664664
}
665665

666-
// Go through the crate metadata and load any crates that it references
666+
/// Go through the crate metadata and load any crates that it references.
667667
fn resolve_crate_deps(
668668
&mut self,
669-
root: &CratePaths,
669+
dep_root: &CratePaths,
670670
crate_root: &CrateRoot,
671671
metadata: &MetadataBlob,
672672
krate: CrateNum,
673673
dep_kind: CrateDepKind,
674674
) -> Result<CrateNumMap, CrateError> {
675-
debug!("resolving deps of external crate");
675+
debug!(
676+
"resolving deps of external crate `{}` with dep root `{}`",
677+
crate_root.name(),
678+
dep_root.name
679+
);
676680
if crate_root.is_proc_macro_crate() {
677681
return Ok(CrateNumMap::new());
678682
}
@@ -685,14 +689,17 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
685689
crate_num_map.push(krate);
686690
for dep in deps {
687691
info!(
688-
"resolving dep crate {} hash: `{}` extra filename: `{}`",
689-
dep.name, dep.hash, dep.extra_filename
692+
"resolving dep `{}`->`{}` hash: `{}` extra filename: `{}`",
693+
crate_root.name(),
694+
dep.name,
695+
dep.hash,
696+
dep.extra_filename
690697
);
691698
let dep_kind = match dep_kind {
692699
CrateDepKind::MacrosOnly => CrateDepKind::MacrosOnly,
693700
_ => dep.kind,
694701
};
695-
let cnum = self.maybe_resolve_crate(dep.name, dep_kind, Some((root, &dep)))?;
702+
let cnum = self.maybe_resolve_crate(dep.name, dep_kind, Some((dep_root, &dep)))?;
696703
crate_num_map.push(cnum);
697704
}
698705

compiler/rustc_metadata/src/locator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,10 @@ impl<'a> CrateLocator<'a> {
765765
self.extract_lib(rlibs, rmetas, dylibs).map(|opt| opt.map(|(_, lib)| lib))
766766
}
767767

768-
pub(crate) fn into_error(self, root: Option<CratePaths>) -> CrateError {
768+
pub(crate) fn into_error(self, dep_root: Option<CratePaths>) -> CrateError {
769769
CrateError::LocatorCombined(Box::new(CombinedLocatorError {
770770
crate_name: self.crate_name,
771-
root,
771+
dep_root,
772772
triple: self.tuple,
773773
dll_prefix: self.target.dll_prefix.to_string(),
774774
dll_suffix: self.target.dll_suffix.to_string(),
@@ -914,7 +914,7 @@ struct CrateRejections {
914914
/// otherwise they are ignored.
915915
pub(crate) struct CombinedLocatorError {
916916
crate_name: Symbol,
917-
root: Option<CratePaths>,
917+
dep_root: Option<CratePaths>,
918918
triple: TargetTuple,
919919
dll_prefix: String,
920920
dll_suffix: String,
@@ -987,7 +987,7 @@ impl CrateError {
987987
}
988988
CrateError::LocatorCombined(locator) => {
989989
let crate_name = locator.crate_name;
990-
let add_info = match &locator.root {
990+
let add_info = match &locator.dep_root {
991991
None => String::new(),
992992
Some(r) => format!(" which `{}` depends on", r.name),
993993
};
@@ -1012,7 +1012,7 @@ impl CrateError {
10121012
path.display()
10131013
));
10141014
}
1015-
if let Some(r) = locator.root {
1015+
if let Some(r) = locator.dep_root {
10161016
for path in r.source.paths() {
10171017
found_crates.push_str(&format!(
10181018
"\ncrate `{}`: {}",

0 commit comments

Comments
 (0)