diff --git a/src/librustc/ich/impls_cstore.rs b/src/librustc/ich/impls_cstore.rs index 0e33c64333dab..d885bd43bc89d 100644 --- a/src/librustc/ich/impls_cstore.rs +++ b/src/librustc/ich/impls_cstore.rs @@ -12,7 +12,6 @@ //! from rustc::middle::cstore in no particular order. use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; -use ich::StableHashingContext; use middle; @@ -50,29 +49,15 @@ impl_stable_hash_for!(enum middle::cstore::LinkagePreference { impl_stable_hash_for!(struct middle::cstore::ExternCrate { src, span, + path_len, direct }); -impl<'a> HashStable> for middle::cstore::ExternCrateSource { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { - use middle::cstore::ExternCrateSource::*; - - ::std::mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - Extern { def_id, path_len } => { - def_id.hash_stable(hcx, hasher); - path_len.hash_stable(hcx, hasher); - } - Use { path_len } => path_len.hash_stable(hcx, hasher), - Path => {} - } - } -} +impl_stable_hash_for!(enum middle::cstore::ExternCrateSource { + Extern(def_id), + Use, + Path, +}); impl_stable_hash_for!(struct middle::cstore::CrateSource { dylib, diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 6208a8a767c10..81fe723deb905 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -153,6 +153,10 @@ pub struct ExternCrate { /// span of the extern crate that caused this to be loaded pub span: Span, + /// Number of links to reach the extern; + /// used to select the extern with the shortest path + pub path_len: usize, + /// If true, then this crate is the crate named by the extern /// crate referenced above. If false, then this crate is a dep /// of the crate. @@ -162,21 +166,14 @@ pub struct ExternCrate { #[derive(Copy, Clone, Debug)] pub enum ExternCrateSource { /// Crate is loaded by `extern crate`. - Extern { + Extern( /// def_id of the item in the current crate that caused /// this crate to be loaded; note that there could be multiple /// such ids - def_id: DefId, - - /// Number of links to reach the extern crate `def_id` - /// declaration; used to select the extern crate with the shortest - /// path - path_len: usize, - }, + DefId, + ), // Crate is loaded by `use`. - Use { - path_len: usize, - }, + Use, /// Crate is implicitly loaded by an absolute or an `extern::` path. Path, } diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 771bdcc55e397..8189064db6968 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -104,7 +104,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { if cnum != LOCAL_CRATE { let opt_extern_crate = self.extern_crate(cnum.as_def_id()); if let Some(ExternCrate { - src: ExternCrateSource::Extern { def_id, .. }, + src: ExternCrateSource::Extern(def_id), direct: true, .. }) = *opt_extern_crate @@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { if cur_def.index == CRATE_DEF_INDEX { match *self.extern_crate(cur_def) { Some(ExternCrate { - src: ExternCrateSource::Extern { def_id, .. }, + src: ExternCrateSource::Extern(def_id), direct: true, .. }) => { diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 268624cf43093..f6692579ffa33 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -367,14 +367,6 @@ impl<'a> CrateLoader<'a> { let cmeta = self.cstore.get_crate_data(cnum); let mut old_extern_crate = cmeta.extern_crate.borrow_mut(); - fn path_len_reverse(src: ExternCrateSource) -> cmp::Reverse { - cmp::Reverse(match src { - ExternCrateSource::Extern { path_len, .. } | - ExternCrateSource::Use { path_len } => path_len, - _ => usize::max_value(), - }) - } - // Prefer: // - something over nothing (tuple.0); // - direct extern crate to indirect (tuple.1); @@ -382,14 +374,14 @@ impl<'a> CrateLoader<'a> { let new_rank = ( true, extern_crate.direct, - path_len_reverse(extern_crate.src), + cmp::Reverse(extern_crate.path_len), ); let old_rank = match *old_extern_crate { None => (false, false, cmp::Reverse(usize::max_value())), Some(ref c) => ( true, c.direct, - path_len_reverse(c.src), + cmp::Reverse(c.path_len), ), }; if old_rank >= new_rank { @@ -1089,8 +1081,9 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> { self.update_extern_crate( cnum, ExternCrate { - src: ExternCrateSource::Extern { def_id, path_len }, + src: ExternCrateSource::Extern(def_id), span: item.span, + path_len, direct: true, }, &mut FxHashSet(), @@ -1116,6 +1109,8 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> { ExternCrate { src: ExternCrateSource::Path, span, + // to have the least priority in `update_extern_crate` + path_len: usize::max_value(), direct: true, }, &mut FxHashSet(), @@ -1141,8 +1136,9 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> { self.update_extern_crate( cnum, ExternCrate { - src: ExternCrateSource::Use { path_len }, + src: ExternCrateSource::Use, span, + path_len, direct: true, }, &mut FxHashSet(),