Skip to content

Commit 69a021f

Browse files
committed
Make CrateMetadata dep_kind private
1 parent 147d03c commit 69a021f

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn dump_crates(cstore: &CStore) {
4949
info!(" name: {}", data.root.name);
5050
info!(" cnum: {}", data.cnum);
5151
info!(" hash: {}", data.root.hash);
52-
info!(" reqd: {:?}", *data.dep_kind.lock());
52+
info!(" reqd: {:?}", data.get_dep_kind());
5353
let CrateSource { dylib, rlib, rmeta } = data.source.clone();
5454
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
5555
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
@@ -375,9 +375,7 @@ impl<'a> CrateLoader<'a> {
375375
if data.root.proc_macro_data.is_some() {
376376
dep_kind = DepKind::UnexportedMacrosOnly;
377377
}
378-
data.dep_kind.with_lock(|data_dep_kind| {
379-
*data_dep_kind = cmp::max(*data_dep_kind, dep_kind);
380-
});
378+
data.set_max_dep_kind(dep_kind);
381379
Ok(cnum)
382380
}
383381
(LoadResult::Loaded(library), host_library) => {
@@ -549,7 +547,7 @@ impl<'a> CrateLoader<'a> {
549547
// #![panic_runtime] crate.
550548
self.inject_dependency_if(cnum, "a panic runtime",
551549
&|data| data.root.needs_panic_runtime);
552-
runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
550+
runtime_found = runtime_found || data.get_dep_kind() == DepKind::Explicit;
553551
}
554552
});
555553

src/librustc_metadata/cstore.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use syntax_expand::base::{SyntaxExtensionKind, SyntaxExtension};
3030
use syntax_expand::proc_macro::{AttrProcMacro, ProcMacroDerive, BangProcMacro};
3131
use syntax_pos::{self, Span, Pos, DUMMY_SP, hygiene::MacroKind};
3232
use syntax_pos::symbol::{Symbol, sym};
33+
use std::cmp;
3334

3435
pub use crate::cstore_impl::{provide, provide_extern};
3536

@@ -96,7 +97,7 @@ crate struct CrateMetadata {
9697
/// Same ID set as `cnum_map` plus maybe some injected crates like panic runtime.
9798
crate dependencies: Lock<Vec<CrateNum>>,
9899
/// How to link (or not link) this crate to the currently compiled crate.
99-
crate dep_kind: Lock<DepKind>,
100+
dep_kind: Lock<DepKind>,
100101
/// Filesystem location of this crate.
101102
crate source: CrateSource,
102103
/// Whether or not this crate should be consider a private dependency
@@ -446,6 +447,23 @@ impl<'a, 'tcx> CrateMetadata {
446447
}
447448
}
448449

450+
crate fn get_dep_kind(&self) -> DepKind {
451+
*self.dep_kind.lock()
452+
}
453+
454+
crate fn export_macros_untracked(&self) {
455+
let mut dep_kind = self.dep_kind.lock();
456+
if *dep_kind == DepKind::UnexportedMacrosOnly {
457+
*dep_kind = DepKind::MacrosOnly;
458+
}
459+
}
460+
461+
crate fn set_max_dep_kind(&self, dep_kind: DepKind) {
462+
self.dep_kind.with_lock(|data_dep_kind| {
463+
*data_dep_kind = cmp::max(*data_dep_kind, dep_kind);
464+
});
465+
}
466+
449467
/// Iterates over the diagnostic items in the given crate.
450468
crate fn get_diagnostic_items(
451469
&self,

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::foreign_modules;
66
use crate::schema;
77

88
use rustc::ty::query::QueryConfig;
9-
use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind};
9+
use rustc::middle::cstore::{CrateSource, CrateStore, EncodedMetadata, NativeLibraryKind};
1010
use rustc::middle::exported_symbols::ExportedSymbol;
1111
use rustc::middle::stability::DeprecationEntry;
1212
use rustc::middle::dependency_format::Linkage;
@@ -210,8 +210,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
210210

211211
visibility => { cdata.get_visibility(def_id.index) }
212212
dep_kind => {
213-
let r = *cdata.dep_kind.lock();
214-
r
213+
cdata.get_dep_kind()
215214
}
216215
crate_name => { cdata.root.name }
217216
item_children => {
@@ -404,10 +403,7 @@ pub fn provide(providers: &mut Providers<'_>) {
404403
impl cstore::CStore {
405404
pub fn export_macros_untracked(&self, cnum: CrateNum) {
406405
let data = self.get_crate_data(cnum);
407-
let mut dep_kind = data.dep_kind.lock();
408-
if *dep_kind == DepKind::UnexportedMacrosOnly {
409-
*dep_kind = DepKind::MacrosOnly;
410-
}
406+
data.export_macros_untracked();
411407
}
412408

413409
pub fn struct_field_names_untracked(&self, def: DefId, sess: &Session) -> Vec<Spanned<Symbol>> {

0 commit comments

Comments
 (0)