1
Fork 0

do not access inherited_impls map directly

This commit is contained in:
Niko Matsakis 2017-04-18 10:53:35 -04:00
parent ace517da0d
commit f35ff22fe8
3 changed files with 20 additions and 17 deletions

View file

@ -475,14 +475,13 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
// This is done to handle the case where, for example, the static // This is done to handle the case where, for example, the static
// method of a private type is used, but the type itself is never // method of a private type is used, but the type itself is never
// called directly. // called directly.
if let Some(impl_list) = let def_id = self.tcx.hir.local_def_id(id);
self.tcx.maps.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) { let inherent_impls = self.tcx.inherent_impls(def_id);
for &impl_did in impl_list.iter() { for &impl_did in inherent_impls.iter() {
for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] { for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] {
if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) { if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) {
if self.live_symbols.contains(&item_node_id) { if self.live_symbols.contains(&item_node_id) {
return true; return true;
}
} }
} }
} }

View file

@ -626,14 +626,14 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
// Encodes the inherent implementations of a structure, enumeration, or trait. // Encodes the inherent implementations of a structure, enumeration, or trait.
fn encode_inherent_implementations(&mut self, def_id: DefId) -> LazySeq<DefIndex> { fn encode_inherent_implementations(&mut self, def_id: DefId) -> LazySeq<DefIndex> {
debug!("EntryBuilder::encode_inherent_implementations({:?})", def_id); debug!("EntryBuilder::encode_inherent_implementations({:?})", def_id);
match self.tcx.maps.inherent_impls.borrow().get(&def_id) { let implementations = self.tcx.inherent_impls(def_id);
None => LazySeq::empty(), if implementations.is_empty() {
Some(implementations) => { LazySeq::empty()
self.lazy_seq(implementations.iter().map(|&def_id| { } else {
assert!(def_id.is_local()); self.lazy_seq(implementations.iter().map(|&def_id| {
def_id.index assert!(def_id.is_local());
})) def_id.index
} }))
} }
} }

View file

@ -66,11 +66,15 @@ pub fn inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// //
// [the plan]: https://github.com/rust-lang/rust-roadmap/issues/4 // [the plan]: https://github.com/rust-lang/rust-roadmap/issues/4
thread_local! {
static EMPTY_DEF_ID_VEC: Rc<Vec<DefId>> = Rc::new(vec![])
}
let result = tcx.dep_graph.with_ignore(|| { let result = tcx.dep_graph.with_ignore(|| {
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate); let crate_map = tcx.crate_inherent_impls(ty_def_id.krate);
match crate_map.inherent_impls.get(&ty_def_id) { match crate_map.inherent_impls.get(&ty_def_id) {
Some(v) => v.clone(), Some(v) => v.clone(),
None => Rc::new(vec![]), None => EMPTY_DEF_ID_VEC.with(|v| v.clone())
} }
}); });