remove the destructors table
This commit is contained in:
parent
346088b555
commit
f9b703e7ab
@ -348,13 +348,17 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
// this properly would result in the necessity of computing *type*
|
||||
// reachability, which might result in a compile time loss.
|
||||
fn mark_destructors_reachable(&mut self) {
|
||||
for adt in self.tcx.adt_defs() {
|
||||
if let Some(destructor_def_id) = adt.destructor() {
|
||||
if destructor_def_id.is_local() {
|
||||
self.reachable_symbols.insert(destructor_def_id.node);
|
||||
let drop_trait = match self.tcx.lang_items.drop_trait() {
|
||||
Some(id) => self.tcx.lookup_trait_def(id), None => { return }
|
||||
};
|
||||
drop_trait.for_each_impl(self.tcx, |drop_impl| {
|
||||
for destructor in &self.tcx.impl_items.borrow()[&drop_impl] {
|
||||
let destructor_did = destructor.def_id();
|
||||
if destructor_did.is_local() {
|
||||
self.reachable_symbols.insert(destructor_did.node);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,9 +245,6 @@ pub struct ctxt<'tcx> {
|
||||
/// True if the variance has been computed yet; false otherwise.
|
||||
pub variance_computed: Cell<bool>,
|
||||
|
||||
/// A method will be in this list if and only if it is a destructor.
|
||||
pub destructors: RefCell<DefIdSet>,
|
||||
|
||||
/// Maps a DefId of a type to a list of its inherent impls.
|
||||
/// Contains implementations of methods that are inherent to a type.
|
||||
/// Methods in these implementations don't need to be exported.
|
||||
@ -475,7 +472,6 @@ impl<'tcx> ctxt<'tcx> {
|
||||
normalized_cache: RefCell::new(FnvHashMap()),
|
||||
lang_items: lang_items,
|
||||
provided_method_sources: RefCell::new(DefIdMap()),
|
||||
destructors: RefCell::new(DefIdSet()),
|
||||
inherent_impls: RefCell::new(DefIdMap()),
|
||||
impl_items: RefCell::new(DefIdMap()),
|
||||
used_unsafe: RefCell::new(NodeSet()),
|
||||
|
@ -2329,11 +2329,6 @@ impl<'tcx> ctxt<'tcx> {
|
||||
self.lookup_adt_def_master(did)
|
||||
}
|
||||
|
||||
/// Return the list of all interned ADT definitions
|
||||
pub fn adt_defs(&self) -> Vec<AdtDef<'tcx>> {
|
||||
self.adt_defs.borrow().values().cloned().collect()
|
||||
}
|
||||
|
||||
/// Given the did of an item, returns its full set of predicates.
|
||||
pub fn lookup_predicates(&self, did: DefId) -> GenericPredicates<'tcx> {
|
||||
lookup_locally_or_in_crate_store(
|
||||
|
@ -1213,15 +1213,14 @@ impl LintPass for DropWithReprExtern {
|
||||
|
||||
impl LateLintPass for DropWithReprExtern {
|
||||
fn check_crate(&mut self, ctx: &LateContext, _: &hir::Crate) {
|
||||
for dtor_did in ctx.tcx.destructors.borrow().iter() {
|
||||
let (drop_impl_did, dtor_self_type) =
|
||||
if dtor_did.is_local() {
|
||||
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
|
||||
let ty = ctx.tcx.lookup_item_type(impl_did).ty;
|
||||
(impl_did, ty)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
let drop_trait = match ctx.tcx.lang_items.drop_trait() {
|
||||
Some(id) => ctx.tcx.lookup_trait_def(id), None => { return }
|
||||
};
|
||||
drop_trait.for_each_impl(ctx.tcx, |drop_impl_did| {
|
||||
if !drop_impl_did.is_local() {
|
||||
return;
|
||||
}
|
||||
let dtor_self_type = ctx.tcx.lookup_item_type(drop_impl_did).ty;
|
||||
|
||||
match dtor_self_type.sty {
|
||||
ty::TyEnum(self_type_def, _) |
|
||||
@ -1247,6 +1246,6 @@ impl LateLintPass for DropWithReprExtern {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -620,13 +620,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
|
||||
ty::TraitContainer(trait_def_id) => {
|
||||
callee::check_legal_trait_for_method_call(self.fcx.ccx, self.span, trait_def_id)
|
||||
}
|
||||
ty::ImplContainer(..) => {
|
||||
// Since `drop` is a trait method, we expect that any
|
||||
// potential calls to it will wind up in the other
|
||||
// arm. But just to be sure, check that the method id
|
||||
// does not appear in the list of destructors.
|
||||
assert!(!self.tcx().destructors.borrow().contains(&pick.item.def_id()));
|
||||
}
|
||||
ty::ImplContainer(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,9 +431,11 @@ pub fn check_item_bodies(ccx: &CrateCtxt) {
|
||||
}
|
||||
|
||||
pub fn check_drop_impls(ccx: &CrateCtxt) {
|
||||
for drop_method_did in ccx.tcx.destructors.borrow().iter() {
|
||||
if drop_method_did.is_local() {
|
||||
let drop_impl_did = ccx.tcx.map.get_parent_did(drop_method_did.node);
|
||||
let drop_trait = match ccx.tcx.lang_items.drop_trait() {
|
||||
Some(id) => ccx.tcx.lookup_trait_def(id), None => { return }
|
||||
};
|
||||
drop_trait.for_each_impl(ccx.tcx, |drop_impl_did| {
|
||||
if drop_impl_did.is_local() {
|
||||
match dropck::check_drop_impl(ccx.tcx, drop_impl_did) {
|
||||
Ok(()) => {}
|
||||
Err(()) => {
|
||||
@ -441,7 +443,7 @@ pub fn check_drop_impls(ccx: &CrateCtxt) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ccx.tcx.sess.abort_if_errors();
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
||||
// Populate the table of destructors. It might seem a bit strange to
|
||||
// do this here, but it's actually the most convenient place, since
|
||||
// the coherence tables contain the trait -> type mappings.
|
||||
self.populate_destructor_table();
|
||||
self.populate_destructors();
|
||||
|
||||
// Check to make sure implementations of `Copy` are legal.
|
||||
self.check_implementations_of_copy();
|
||||
@ -286,7 +286,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
||||
// Destructors
|
||||
//
|
||||
|
||||
fn populate_destructor_table(&self) {
|
||||
fn populate_destructors(&self) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
let drop_trait = match tcx.lang_items.drop_trait() {
|
||||
Some(id) => id, None => { return }
|
||||
@ -309,9 +309,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
||||
ty::TyEnum(type_def, _) |
|
||||
ty::TyStruct(type_def, _) => {
|
||||
type_def.set_destructor(method_def_id.def_id());
|
||||
tcx.destructors
|
||||
.borrow_mut()
|
||||
.insert(method_def_id.def_id());
|
||||
}
|
||||
_ => {
|
||||
// Destructors only work on nominal types.
|
||||
|
Loading…
Reference in New Issue
Block a user