Skip to content

Commit 3b1d60a

Browse files
committed
rustc_metadata: Privatize CrateMetadata::root
1 parent a9cef49 commit 3b1d60a

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/librustc_metadata/creader.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub struct CrateLoader<'a> {
4747
fn dump_crates(cstore: &CStore) {
4848
info!("resolved crates:");
4949
cstore.iter_crate_data(|cnum, data| {
50-
info!(" name: {}", data.root.name());
50+
info!(" name: {}", data.name());
5151
info!(" cnum: {}", cnum);
52-
info!(" hash: {}", data.root.hash());
52+
info!(" hash: {}", data.hash());
5353
info!(" reqd: {:?}", data.dep_kind());
5454
let CrateSource { dylib, rlib, rmeta } = data.source();
5555
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
@@ -101,10 +101,10 @@ impl<'a> CrateLoader<'a> {
101101
-> Option<CrateNum> {
102102
let mut ret = None;
103103
self.cstore.iter_crate_data(|cnum, data| {
104-
if data.root.name() != name { return }
104+
if data.name() != name { return }
105105

106106
match hash {
107-
Some(hash) if *hash == data.root.hash() => { ret = Some(cnum); return }
107+
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
108108
Some(..) => return,
109109
None => {}
110110
}
@@ -164,9 +164,9 @@ impl<'a> CrateLoader<'a> {
164164

165165
// Check for conflicts with any crate loaded so far
166166
self.cstore.iter_crate_data(|_, other| {
167-
if other.root.name() == root.name() && // same crate-name
168-
other.root.disambiguator() == root.disambiguator() && // same crate-disambiguator
169-
other.root.hash() != root.hash() { // but different SVH
167+
if other.name() == root.name() && // same crate-name
168+
other.disambiguator() == root.disambiguator() && // same crate-disambiguator
169+
other.hash() != root.hash() { // but different SVH
170170
span_fatal!(self.sess, span, E0523,
171171
"found two different crates with name `{}` that are \
172172
not distinguished by differing `-C metadata`. This \
@@ -350,7 +350,7 @@ impl<'a> CrateLoader<'a> {
350350
match result {
351351
(LoadResult::Previous(cnum), None) => {
352352
let data = self.cstore.get_crate_data(cnum);
353-
if data.root.is_proc_macro_crate() {
353+
if data.is_proc_macro_crate() {
354354
dep_kind = DepKind::UnexportedMacrosOnly;
355355
}
356356
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
@@ -378,7 +378,7 @@ impl<'a> CrateLoader<'a> {
378378
if locator.triple == self.sess.opts.target_triple {
379379
let mut result = LoadResult::Loaded(library);
380380
self.cstore.iter_crate_data(|cnum, data| {
381-
if data.root.name() == root.name() && root.hash() == data.root.hash() {
381+
if data.name() == root.name() && root.hash() == data.hash() {
382382
assert!(locator.hash.is_none());
383383
info!("load success, going to previous cnum: {}", cnum);
384384
result = LoadResult::Previous(cnum);
@@ -621,7 +621,7 @@ impl<'a> CrateLoader<'a> {
621621

622622
let mut uses_std = false;
623623
self.cstore.iter_crate_data(|_, data| {
624-
if data.root.name() == sym::std {
624+
if data.name() == sym::std {
625625
uses_std = true;
626626
}
627627
});
@@ -731,14 +731,14 @@ impl<'a> CrateLoader<'a> {
731731
conflicts with this global \
732732
allocator in: {}",
733733
other_crate,
734-
data.root.name()));
734+
data.name()));
735735
}
736736
Some(None) => {
737737
self.sess.err(&format!("the `#[global_allocator]` in this \
738738
crate conflicts with global \
739-
allocator in: {}", data.root.name()));
739+
allocator in: {}", data.name()));
740740
}
741-
None => global_allocator = Some(Some(data.root.name())),
741+
None => global_allocator = Some(Some(data.name())),
742742
}
743743
});
744744
if global_allocator.is_some() {
@@ -786,9 +786,9 @@ impl<'a> CrateLoader<'a> {
786786
self.sess.err(&format!("the crate `{}` cannot depend \
787787
on a crate that needs {}, but \
788788
it depends on `{}`",
789-
self.cstore.get_crate_data(krate).root.name(),
789+
self.cstore.get_crate_data(krate).name(),
790790
what,
791-
data.root.name()));
791+
data.name()));
792792
}
793793
}
794794

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ crate struct CrateMetadata {
6666
/// lifetime is only used behind `Lazy`, and therefore acts like an
6767
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
6868
/// is being used to decode those values.
69-
crate root: CrateRoot<'static>,
69+
root: CrateRoot<'static>,
7070
/// For each definition in this crate, we encode a key. When the
7171
/// crate is loaded, we read all the keys and put them in this
7272
/// hashmap, which gives the reverse mapping. This allows us to
@@ -1594,6 +1594,22 @@ impl<'a, 'tcx> CrateMetadata {
15941594
crate fn has_default_lib_allocator(&self) -> bool {
15951595
self.root.has_default_lib_allocator
15961596
}
1597+
1598+
crate fn is_proc_macro_crate(&self) -> bool {
1599+
self.root.is_proc_macro_crate()
1600+
}
1601+
1602+
crate fn name(&self) -> Symbol {
1603+
self.root.name
1604+
}
1605+
1606+
crate fn disambiguator(&self) -> CrateDisambiguator {
1607+
self.root.disambiguator
1608+
}
1609+
1610+
crate fn hash(&self) -> Svh {
1611+
self.root.hash
1612+
}
15971613
}
15981614

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

0 commit comments

Comments
 (0)