Skip to content

Commit f9b703e

Browse files
committed
remove the destructors table
1 parent 346088b commit f9b703e

File tree

7 files changed

+27
-40
lines changed

7 files changed

+27
-40
lines changed

src/librustc/middle/reachable.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,17 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
348348
// this properly would result in the necessity of computing *type*
349349
// reachability, which might result in a compile time loss.
350350
fn mark_destructors_reachable(&mut self) {
351-
for adt in self.tcx.adt_defs() {
352-
if let Some(destructor_def_id) = adt.destructor() {
353-
if destructor_def_id.is_local() {
354-
self.reachable_symbols.insert(destructor_def_id.node);
351+
let drop_trait = match self.tcx.lang_items.drop_trait() {
352+
Some(id) => self.tcx.lookup_trait_def(id), None => { return }
353+
};
354+
drop_trait.for_each_impl(self.tcx, |drop_impl| {
355+
for destructor in &self.tcx.impl_items.borrow()[&drop_impl] {
356+
let destructor_did = destructor.def_id();
357+
if destructor_did.is_local() {
358+
self.reachable_symbols.insert(destructor_did.node);
355359
}
356360
}
357-
}
361+
})
358362
}
359363
}
360364

src/librustc/middle/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ pub struct ctxt<'tcx> {
245245
/// True if the variance has been computed yet; false otherwise.
246246
pub variance_computed: Cell<bool>,
247247

248-
/// A method will be in this list if and only if it is a destructor.
249-
pub destructors: RefCell<DefIdSet>,
250-
251248
/// Maps a DefId of a type to a list of its inherent impls.
252249
/// Contains implementations of methods that are inherent to a type.
253250
/// Methods in these implementations don't need to be exported.
@@ -475,7 +472,6 @@ impl<'tcx> ctxt<'tcx> {
475472
normalized_cache: RefCell::new(FnvHashMap()),
476473
lang_items: lang_items,
477474
provided_method_sources: RefCell::new(DefIdMap()),
478-
destructors: RefCell::new(DefIdSet()),
479475
inherent_impls: RefCell::new(DefIdMap()),
480476
impl_items: RefCell::new(DefIdMap()),
481477
used_unsafe: RefCell::new(NodeSet()),

src/librustc/middle/ty/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2329,11 +2329,6 @@ impl<'tcx> ctxt<'tcx> {
23292329
self.lookup_adt_def_master(did)
23302330
}
23312331

2332-
/// Return the list of all interned ADT definitions
2333-
pub fn adt_defs(&self) -> Vec<AdtDef<'tcx>> {
2334-
self.adt_defs.borrow().values().cloned().collect()
2335-
}
2336-
23372332
/// Given the did of an item, returns its full set of predicates.
23382333
pub fn lookup_predicates(&self, did: DefId) -> GenericPredicates<'tcx> {
23392334
lookup_locally_or_in_crate_store(

src/librustc_lint/builtin.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1213,15 +1213,14 @@ impl LintPass for DropWithReprExtern {
12131213

12141214
impl LateLintPass for DropWithReprExtern {
12151215
fn check_crate(&mut self, ctx: &LateContext, _: &hir::Crate) {
1216-
for dtor_did in ctx.tcx.destructors.borrow().iter() {
1217-
let (drop_impl_did, dtor_self_type) =
1218-
if dtor_did.is_local() {
1219-
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
1220-
let ty = ctx.tcx.lookup_item_type(impl_did).ty;
1221-
(impl_did, ty)
1222-
} else {
1223-
continue;
1224-
};
1216+
let drop_trait = match ctx.tcx.lang_items.drop_trait() {
1217+
Some(id) => ctx.tcx.lookup_trait_def(id), None => { return }
1218+
};
1219+
drop_trait.for_each_impl(ctx.tcx, |drop_impl_did| {
1220+
if !drop_impl_did.is_local() {
1221+
return;
1222+
}
1223+
let dtor_self_type = ctx.tcx.lookup_item_type(drop_impl_did).ty;
12251224

12261225
match dtor_self_type.sty {
12271226
ty::TyEnum(self_type_def, _) |
@@ -1247,6 +1246,6 @@ impl LateLintPass for DropWithReprExtern {
12471246
}
12481247
_ => {}
12491248
}
1250-
}
1249+
})
12511250
}
12521251
}

src/librustc_typeck/check/method/confirm.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
620620
ty::TraitContainer(trait_def_id) => {
621621
callee::check_legal_trait_for_method_call(self.fcx.ccx, self.span, trait_def_id)
622622
}
623-
ty::ImplContainer(..) => {
624-
// Since `drop` is a trait method, we expect that any
625-
// potential calls to it will wind up in the other
626-
// arm. But just to be sure, check that the method id
627-
// does not appear in the list of destructors.
628-
assert!(!self.tcx().destructors.borrow().contains(&pick.item.def_id()));
629-
}
623+
ty::ImplContainer(..) => {}
630624
}
631625
}
632626

src/librustc_typeck/check/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,19 @@ pub fn check_item_bodies(ccx: &CrateCtxt) {
431431
}
432432

433433
pub fn check_drop_impls(ccx: &CrateCtxt) {
434-
for drop_method_did in ccx.tcx.destructors.borrow().iter() {
435-
if drop_method_did.is_local() {
436-
let drop_impl_did = ccx.tcx.map.get_parent_did(drop_method_did.node);
434+
let drop_trait = match ccx.tcx.lang_items.drop_trait() {
435+
Some(id) => ccx.tcx.lookup_trait_def(id), None => { return }
436+
};
437+
drop_trait.for_each_impl(ccx.tcx, |drop_impl_did| {
438+
if drop_impl_did.is_local() {
437439
match dropck::check_drop_impl(ccx.tcx, drop_impl_did) {
438440
Ok(()) => {}
439441
Err(()) => {
440442
assert!(ccx.tcx.sess.has_errors());
441443
}
442444
}
443445
}
444-
}
446+
});
445447

446448
ccx.tcx.sess.abort_if_errors();
447449
}

src/librustc_typeck/coherence/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
126126
// Populate the table of destructors. It might seem a bit strange to
127127
// do this here, but it's actually the most convenient place, since
128128
// the coherence tables contain the trait -> type mappings.
129-
self.populate_destructor_table();
129+
self.populate_destructors();
130130

131131
// Check to make sure implementations of `Copy` are legal.
132132
self.check_implementations_of_copy();
@@ -286,7 +286,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
286286
// Destructors
287287
//
288288

289-
fn populate_destructor_table(&self) {
289+
fn populate_destructors(&self) {
290290
let tcx = self.crate_context.tcx;
291291
let drop_trait = match tcx.lang_items.drop_trait() {
292292
Some(id) => id, None => { return }
@@ -309,9 +309,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
309309
ty::TyEnum(type_def, _) |
310310
ty::TyStruct(type_def, _) => {
311311
type_def.set_destructor(method_def_id.def_id());
312-
tcx.destructors
313-
.borrow_mut()
314-
.insert(method_def_id.def_id());
315312
}
316313
_ => {
317314
// Destructors only work on nominal types.

0 commit comments

Comments
 (0)