Skip to content

Commit e19e594

Browse files
committed
do not access inherited_impls map directly
1 parent 0ee56f6 commit e19e594

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/librustc/middle/dead.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,13 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
475475
// This is done to handle the case where, for example, the static
476476
// method of a private type is used, but the type itself is never
477477
// called directly.
478-
if let Some(impl_list) =
479-
self.tcx.maps.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) {
480-
for &impl_did in impl_list.iter() {
481-
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
482-
if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
483-
if self.live_symbols.contains(&item_node_id) {
484-
return true;
485-
}
478+
let def_id = self.tcx.hir.local_def_id(id);
479+
let inherent_impls = self.tcx.inherent_impls(def_id);
480+
for &impl_did in inherent_impls.iter() {
481+
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
482+
if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
483+
if self.live_symbols.contains(&item_node_id) {
484+
return true;
486485
}
487486
}
488487
}

src/librustc_metadata/encoder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,14 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
626626
// Encodes the inherent implementations of a structure, enumeration, or trait.
627627
fn encode_inherent_implementations(&mut self, def_id: DefId) -> LazySeq<DefIndex> {
628628
debug!("EntryBuilder::encode_inherent_implementations({:?})", def_id);
629-
match self.tcx.maps.inherent_impls.borrow().get(&def_id) {
630-
None => LazySeq::empty(),
631-
Some(implementations) => {
632-
self.lazy_seq(implementations.iter().map(|&def_id| {
633-
assert!(def_id.is_local());
634-
def_id.index
635-
}))
636-
}
629+
let implementations = self.tcx.inherent_impls(def_id);
630+
if implementations.is_empty() {
631+
LazySeq::empty()
632+
} else {
633+
self.lazy_seq(implementations.iter().map(|&def_id| {
634+
assert!(def_id.is_local());
635+
def_id.index
636+
}))
637637
}
638638
}
639639

src/librustc_typeck/coherence/inherent_impls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ pub fn inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6666
//
6767
// [the plan]: https://github.com/rust-lang/rust-roadmap/issues/4
6868

69+
thread_local! {
70+
static EMPTY_DEF_ID_VEC: Rc<Vec<DefId>> = Rc::new(vec![])
71+
}
72+
6973
let result = tcx.dep_graph.with_ignore(|| {
7074
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate);
7175
match crate_map.inherent_impls.get(&ty_def_id) {
7276
Some(v) => v.clone(),
73-
None => Rc::new(vec![]),
77+
None => EMPTY_DEF_ID_VEC.with(|v| v.clone())
7478
}
7579
});
7680

0 commit comments

Comments
 (0)