Skip to content
Permalink
Browse files

rustc_metadata: Privatize `CrateMetadata::dep_kind`

  • Loading branch information
petrochenkov committed Nov 23, 2019
1 parent 32aa58c commit 765133ac2e3f74b89417782f71d1aa505579523b
Showing with 12 additions and 6 deletions.
  1. +3 −5 src/librustc_metadata/creader.rs
  2. +9 −1 src/librustc_metadata/rmeta/decoder.rs
@@ -50,7 +50,7 @@ fn dump_crates(cstore: &CStore) {
info!(" name: {}", data.root.name);
info!(" cnum: {}", cnum);
info!(" hash: {}", data.root.hash);
info!(" reqd: {:?}", *data.dep_kind.lock());
info!(" reqd: {:?}", data.dep_kind());
let CrateSource { dylib, rlib, rmeta } = data.source();
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
@@ -353,9 +353,7 @@ impl<'a> CrateLoader<'a> {
if data.root.is_proc_macro_crate() {
dep_kind = DepKind::UnexportedMacrosOnly;
}
data.dep_kind.with_lock(|data_dep_kind| {
*data_dep_kind = cmp::max(*data_dep_kind, dep_kind);
});
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
Ok(cnum)
}
(LoadResult::Loaded(library), host_library) => {
@@ -503,7 +501,7 @@ impl<'a> CrateLoader<'a> {
// #![panic_runtime] crate.
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.root.needs_panic_runtime);
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
runtime_found = runtime_found || data.dep_kind() == DepKind::Explicit;
}
});

@@ -99,7 +99,7 @@ crate struct CrateMetadata {
/// Same ID set as `cnum_map` plus maybe some injected crates like panic runtime.
dependencies: Lock<Vec<CrateNum>>,
/// How to link (or not link) this crate to the currently compiled crate.
crate dep_kind: Lock<DepKind>,
dep_kind: Lock<DepKind>,
/// Filesystem location of this crate.
source: CrateSource,
/// Whether or not this crate should be consider a private dependency
@@ -1538,6 +1538,14 @@ impl<'a, 'tcx> CrateMetadata {
crate fn source(&self) -> &CrateSource {
&self.source
}

crate fn dep_kind(&self) -> DepKind {
*self.dep_kind.lock()
}

crate fn update_dep_kind(&self, f: impl FnOnce(DepKind) -> DepKind) {
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
}
}

// Cannot be implemented on 'ProcMacro', as libproc_macro

0 comments on commit 765133a

Please sign in to comment.
You can’t perform that action at this time.