diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2015-09-26 22:25:49 +0300 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-10-16 15:34:04 -0700 |
| commit | 7eb6ca228ee613205d4105ab74d0bdbbb8e6cafe (patch) | |
| tree | d2deb4c4242eb908c1b10e230471f0c0095c23e4 | |
| parent | fc166d44f02c1d7baa20e2ae2ef20b599cd99ecf (diff) | |
| download | rust-7eb6ca228ee613205d4105ab74d0bdbbb8e6cafe.tar.gz rust-7eb6ca228ee613205d4105ab74d0bdbbb8e6cafe.zip | |
remove the destructors table
Conflicts: src/librustc_lint/builtin.rs
| -rw-r--r-- | src/librustc/middle/reachable.rs | 14 | ||||
| -rw-r--r-- | src/librustc/middle/ty/context.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/ty/mod.rs | 5 | ||||
| -rw-r--r-- | src/librustc_lint/builtin.rs | 20 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/confirm.rs | 8 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustc_typeck/coherence/mod.rs | 7 |
7 files changed, 28 insertions, 40 deletions
diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 215368754c9..03374fa492e 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -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); } } - } + }) } } diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index e3b6da56680..ef9707967f3 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -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()), diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index 4a96260ec1e..59eb5e7a72f 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -2331,11 +2331,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( diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index d90b7d6fac3..717690addde 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2591,16 +2591,16 @@ impl LintPass for DropWithReprExtern { fn get_lints(&self) -> LintArray { lint_array!(DROP_WITH_REPR_EXTERN) } + fn check_crate(&mut self, ctx: &Context, _: &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, _) | @@ -2626,6 +2626,6 @@ impl LintPass for DropWithReprExtern { } _ => {} } - } + }) } } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 572ba7a8487..454c11db263 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -621,13 +621,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(..) => {} } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9dd7cfea43f..9a8f70454ac 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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(); } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 9ba6f1398e4..8cffac67321 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -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. |
