]> git.lizzy.rs Git - rust.git/commitdiff
rustc: remove ImplOrTraitItemId and TraitDef's associated_type_names.
authorEduard Burtescu <edy.burt@gmail.com>
Mon, 5 Sep 2016 07:54:38 +0000 (10:54 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Tue, 20 Sep 2016 17:08:03 +0000 (20:08 +0300)
26 files changed:
src/librustc/dep_graph/dep_node.rs
src/librustc/middle/cstore.rs
src/librustc/middle/dead.rs
src/librustc/middle/stability.rs
src/librustc/traits/specialize/specialization_graph.rs
src/librustc/ty/context.rs
src/librustc/ty/maps.rs
src/librustc/ty/mod.rs
src/librustc/ty/trait_def.rs
src/librustc_const_eval/eval.rs
src/librustc_metadata/common.rs
src/librustc_metadata/csearch.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_save_analysis/lib.rs
src/librustc_trans/meth.rs
src/librustc_trans/mir/constant.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/coherence/mod.rs
src/librustc_typeck/coherence/overlap.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/lib.rs
src/librustdoc/clean/inline.rs

index 3cf7548e3209a5f209a114150b8ece6f13a80bd6..269f0ebb813ca091f6028b60395552790492ab8c 100644 (file)
@@ -108,7 +108,7 @@ pub enum DepNode<D: Clone + Debug> {
     ItemSignature(D),
     FieldTy(D),
     SizedConstraint(D),
-    ImplOrTraitItemIds(D),
+    ImplOrTraitItemDefIds(D),
     InherentImpls(D),
 
     // The set of impls for a given trait. Ultimately, it would be
@@ -157,7 +157,7 @@ macro_rules! check {
             ImplOrTraitItems,
             ItemSignature,
             FieldTy,
-            ImplOrTraitItemIds,
+            ImplOrTraitItemDefIds,
             InherentImpls,
             TraitImpls,
             ReprHints,
@@ -225,7 +225,7 @@ pub fn map_def<E, OP>(&self, mut op: OP) -> Option<DepNode<E>>
             ItemSignature(ref d) => op(d).map(ItemSignature),
             FieldTy(ref d) => op(d).map(FieldTy),
             SizedConstraint(ref d) => op(d).map(SizedConstraint),
-            ImplOrTraitItemIds(ref d) => op(d).map(ImplOrTraitItemIds),
+            ImplOrTraitItemDefIds(ref d) => op(d).map(ImplOrTraitItemDefIds),
             InherentImpls(ref d) => op(d).map(InherentImpls),
             TraitImpls(ref d) => op(d).map(TraitImpls),
             TraitItems(ref d) => op(d).map(TraitItems),
index 52cadd76c64cbeeeb68a66229200185c1509ce6a..e844ec37dc7cd671168ab3cc35f5d26310f50768 100644 (file)
@@ -157,7 +157,7 @@ fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
 
     // impl info
-    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
+    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId>;
     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
                           -> Option<ty::TraitRef<'tcx>>;
     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
@@ -329,7 +329,7 @@ fn def_index_for_def_key(&self,
     }
 
     // impl info
-    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
+    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId>
         { bug!("impl_or_trait_items") }
     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
                           -> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
index 2c952e9f8634964a0d5ba9ce0307e22495c77a1d..70232d4f01e95e8e41e450c85ecd229d32b46996 100644 (file)
@@ -470,13 +470,12 @@ fn symbol_is_live(&mut self,
         // 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
         // called directly.
-        let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
+        let impl_items = self.tcx.impl_or_trait_item_def_ids.borrow();
         if let Some(impl_list) =
                 self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
             for impl_did in impl_list.iter() {
-                for item_did in impl_items.get(impl_did).unwrap().iter() {
-                    if let Some(item_node_id) =
-                            self.tcx.map.as_local_node_id(item_did.def_id()) {
+                for &item_did in &impl_items[impl_did][..] {
+                    if let Some(item_node_id) = self.tcx.map.as_local_node_id(item_did) {
                         if self.live_symbols.contains(&item_node_id) {
                             return true;
                         }
index e2b997ed60f2d70d5f9f6a564a917de9c9f75f09..2c768db47f11a94661c000b9c99ae6167443fc3b 100644 (file)
@@ -695,10 +695,9 @@ fn is_internal<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span) -> bool {
 
 fn is_staged_api<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> bool {
     match tcx.trait_item_of_item(id) {
-        Some(ty::MethodTraitItemId(trait_method_id))
-            if trait_method_id != id => {
-                is_staged_api(tcx, trait_method_id)
-            }
+        Some(trait_method_id) if trait_method_id != id => {
+            is_staged_api(tcx, trait_method_id)
+        }
         _ => {
             *tcx.stability.borrow_mut().staged_api.entry(id.krate).or_insert_with(
                 || tcx.sess.cstore.is_staged_api(id.krate))
index 4339b1a254f2046566e925e7ef0b19cac09994e3..1374719ef49c4875bd7eafe97a4fdd348a414a35 100644 (file)
@@ -304,7 +304,7 @@ pub fn def_id(&self) -> DefId {
 /// An iterator over the items defined within a trait or impl.
 pub struct NodeItems<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    items: Rc<Vec<ty::ImplOrTraitItemId>>,
+    items: Rc<Vec<DefId>>,
     idx: usize
 }
 
@@ -312,7 +312,7 @@ impl<'a, 'tcx> Iterator for NodeItems<'a, 'tcx> {
     type Item = ImplOrTraitItem<'tcx>;
     fn next(&mut self) -> Option<ImplOrTraitItem<'tcx>> {
         if self.idx < self.items.len() {
-            let item_def_id = self.items[self.idx].def_id();
+            let item_def_id = self.items[self.idx];
             let items_table = self.tcx.impl_or_trait_items.borrow();
             let item = items_table[&item_def_id].clone();
             self.idx += 1;
index 0d6beb34c69023944dcc64a8fda12d49455da8a9..1c9238646df297de31c49d8dc60c7eeb651717c6 100644 (file)
@@ -331,7 +331,7 @@ pub struct GlobalCtxt<'tcx> {
     pub impl_or_trait_items: RefCell<DepTrackingMap<maps::ImplOrTraitItems<'tcx>>>,
 
     /// Maps from an impl/trait def-id to a list of the def-ids of its items
-    pub impl_or_trait_item_ids: RefCell<DepTrackingMap<maps::ImplOrTraitItemIds<'tcx>>>,
+    pub impl_or_trait_item_def_ids: RefCell<DepTrackingMap<maps::ImplOrTraitItemDefIds<'tcx>>>,
 
     /// A cache for the trait_items() routine; note that the routine
     /// itself pushes the `TraitItems` dependency node.
@@ -728,7 +728,7 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
             rcache: RefCell::new(FnvHashMap()),
             tc_cache: RefCell::new(FnvHashMap()),
             impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
-            impl_or_trait_item_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
+            impl_or_trait_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
             trait_items_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
             ty_param_defs: RefCell::new(NodeMap()),
             normalized_cache: RefCell::new(FnvHashMap()),
@@ -1396,7 +1396,7 @@ pub fn trait_items(self, trait_did: DefId) -> Rc<Vec<ty::ImplOrTraitItem<'gcx>>>
         self.trait_items_cache.memoize(trait_did, || {
             let def_ids = self.impl_or_trait_items(trait_did);
             Rc::new(def_ids.iter()
-                           .map(|d| self.impl_or_trait_item(d.def_id()))
+                           .map(|&def_id| self.impl_or_trait_item(def_id))
                            .collect())
         })
     }
index 5e029cf98dc6260a8dd02ff325c26c28e6fa2733..3a552a8b437d3aba15ba54929a17f4a48e95c05d 100644 (file)
@@ -34,8 +34,7 @@ fn to_dep_node(key: &$key) -> DepNode<DefId> { DepNode::$node_name(*key) }
 dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics<'tcx> }
 dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
 dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
-dep_map_ty! { ImplOrTraitItemIds: ImplOrTraitItemIds(DefId)
-                                    -> Rc<Vec<ty::ImplOrTraitItemId>> }
+dep_map_ty! { ImplOrTraitItemDefIds: ImplOrTraitItemDefIds(DefId) -> Rc<Vec<DefId>> }
 dep_map_ty! { ImplTraitRefs: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>> }
 dep_map_ty! { TraitDefs: ItemSignature(DefId) -> &'tcx ty::TraitDef<'tcx> }
 dep_map_ty! { AdtDefs: ItemSignature(DefId) -> ty::AdtDefMaster<'tcx> }
index 3eb9f8593e3af8e9eab9703d76f6a310889f7472..8aba6329b090badffc6852e4a8b369e190108f1a 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-pub use self::ImplOrTraitItemId::*;
 pub use self::Variance::*;
 pub use self::DtorKind::*;
 pub use self::ImplOrTraitItemContainer::*;
@@ -190,18 +189,6 @@ pub enum ImplOrTraitItem<'tcx> {
 }
 
 impl<'tcx> ImplOrTraitItem<'tcx> {
-    fn id(&self) -> ImplOrTraitItemId {
-        match *self {
-            ConstTraitItem(ref associated_const) => {
-                ConstTraitItemId(associated_const.def_id)
-            }
-            MethodTraitItem(ref method) => MethodTraitItemId(method.def_id),
-            TypeTraitItem(ref associated_type) => {
-                TypeTraitItemId(associated_type.def_id)
-            }
-        }
-    }
-
     pub fn def(&self) -> Def {
         match *self {
             ConstTraitItem(ref associated_const) => Def::AssociatedConst(associated_const.def_id),
@@ -250,23 +237,6 @@ pub fn as_opt_method(&self) -> Option<Rc<Method<'tcx>>> {
     }
 }
 
-#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable)]
-pub enum ImplOrTraitItemId {
-    ConstTraitItemId(DefId),
-    MethodTraitItemId(DefId),
-    TypeTraitItemId(DefId),
-}
-
-impl ImplOrTraitItemId {
-    pub fn def_id(&self) -> DefId {
-        match *self {
-            ConstTraitItemId(def_id) => def_id,
-            MethodTraitItemId(def_id) => def_id,
-            TypeTraitItemId(def_id) => def_id,
-        }
-    }
-}
-
 #[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable)]
 pub enum Visibility {
     /// Visible everywhere (including in other crates).
@@ -2276,8 +2246,8 @@ pub fn expr_is_lval(self, expr: &hir::Expr) -> bool {
     }
 
     pub fn provided_trait_methods(self, id: DefId) -> Vec<Rc<Method<'gcx>>> {
-        self.impl_or_trait_items(id).iter().filter_map(|id| {
-            match self.impl_or_trait_item(id.def_id()) {
+        self.impl_or_trait_items(id).iter().filter_map(|&def_id| {
+            match self.impl_or_trait_item(def_id) {
                 MethodTraitItem(ref m) if m.has_body => Some(m.clone()),
                 _ => None
             }
@@ -2321,9 +2291,9 @@ pub fn impl_or_trait_item(self, id: DefId) -> ImplOrTraitItem<'gcx> {
                    .expect("missing ImplOrTraitItem in metadata"))
     }
 
-    pub fn impl_or_trait_items(self, id: DefId) -> Rc<Vec<ImplOrTraitItemId>> {
+    pub fn impl_or_trait_items(self, id: DefId) -> Rc<Vec<DefId>> {
         lookup_locally_or_in_crate_store(
-            "impl_or_trait_items", id, &self.impl_or_trait_item_ids,
+            "impl_or_trait_items", id, &self.impl_or_trait_item_def_ids,
             || Rc::new(self.sess.cstore.impl_or_trait_items(id)))
     }
 
@@ -2600,7 +2570,7 @@ pub fn populate_implementations_for_primitive_if_necessary(self,
         let impl_items = self.sess.cstore.impl_or_trait_items(primitive_def_id);
 
         // Store the implementation info.
-        self.impl_or_trait_item_ids.borrow_mut().insert(primitive_def_id, Rc::new(impl_items));
+        self.impl_or_trait_item_def_ids.borrow_mut().insert(primitive_def_id, Rc::new(impl_items));
         self.populated_external_primitive_impls.borrow_mut().insert(primitive_def_id);
     }
 
@@ -2627,7 +2597,7 @@ pub fn populate_inherent_implementations_for_type_if_necessary(self,
         for &impl_def_id in &inherent_impls {
             // Store the implementation info.
             let impl_items = self.sess.cstore.impl_or_trait_items(impl_def_id);
-            self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
+            self.impl_or_trait_item_def_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
         }
 
         self.inherent_impls.borrow_mut().insert(type_id, inherent_impls);
@@ -2669,15 +2639,14 @@ pub fn populate_implementations_for_trait_if_necessary(self, trait_id: DefId) {
 
             // For any methods that use a default implementation, add them to
             // the map. This is a bit unfortunate.
-            for impl_item_def_id in &impl_items {
-                let method_def_id = impl_item_def_id.def_id();
+            for &impl_item_def_id in &impl_items {
                 // load impl items eagerly for convenience
                 // FIXME: we may want to load these lazily
-                self.impl_or_trait_item(method_def_id);
+                self.impl_or_trait_item(impl_item_def_id);
             }
 
             // Store the implementation info.
-            self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
+            self.impl_or_trait_item_def_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
         }
 
         def.flags.set(def.flags.get() | TraitFlags::IMPLS_VALID);
@@ -2766,19 +2735,19 @@ pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
     /// is already that of the original trait method, then the return value is
     /// the same).
     /// Otherwise, return `None`.
-    pub fn trait_item_of_item(self, def_id: DefId) -> Option<ImplOrTraitItemId> {
+    pub fn trait_item_of_item(self, def_id: DefId) -> Option<DefId> {
         let impl_or_trait_item = match self.impl_or_trait_items.borrow().get(&def_id) {
             Some(m) => m.clone(),
             None => return None,
         };
         match impl_or_trait_item.container() {
-            TraitContainer(_) => Some(impl_or_trait_item.id()),
+            TraitContainer(_) => Some(impl_or_trait_item.def_id()),
             ImplContainer(def_id) => {
                 self.trait_id_of_impl(def_id).and_then(|trait_did| {
                     let name = impl_or_trait_item.name();
                     self.trait_items(trait_did).iter()
                         .find(|item| item.name() == name)
-                        .map(|item| item.id())
+                        .map(|item| item.def_id())
                 })
             }
         }
index 268b2fcaa4adbb8687b833a9a06ee6f4cdddab90..3ff2ed76e571e3a8b308657186d9a069331e57cf 100644 (file)
@@ -15,7 +15,6 @@
 use ty::fast_reject;
 use ty::{Ty, TyCtxt, TraitRef};
 use std::cell::{Cell, RefCell};
-use syntax::ast::Name;
 use hir;
 use util::nodemap::FnvHashMap;
 
@@ -38,10 +37,6 @@ pub struct TraitDef<'tcx> {
 
     pub trait_ref: ty::TraitRef<'tcx>,
 
-    /// A list of the associated types defined in this trait. Useful
-    /// for resolving `X::Foo` type markers.
-    pub associated_type_names: Vec<Name>,
-
     // Impls of a trait. To allow for quicker lookup, the impls are indexed by a
     // simplified version of their `Self` type: impls with a simplifiable `Self`
     // are stored in `nonblanket_impls` keyed by it, while all other impls are
@@ -82,7 +77,6 @@ pub fn new(unsafety: hir::Unsafety,
                paren_sugar: bool,
                generics: &'tcx ty::Generics<'tcx>,
                trait_ref: ty::TraitRef<'tcx>,
-               associated_type_names: Vec<Name>,
                def_path_hash: u64)
                -> TraitDef<'tcx> {
         TraitDef {
@@ -90,7 +84,6 @@ pub fn new(unsafety: hir::Unsafety,
             unsafety: unsafety,
             generics: generics,
             trait_ref: trait_ref,
-            associated_type_names: associated_type_names,
             nonblanket_impls: RefCell::new(FnvHashMap()),
             blanket_impls: RefCell::new(vec![]),
             flags: Cell::new(ty::TraitFlags::NO_TRAIT_FLAGS),
index fe3c498d184bebf0e746a19ef6cd40a5e82ae33a..aa53fdd6e7e27f75429bfc6a2829d9f34da86150 100644 (file)
@@ -1081,16 +1081,14 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         match selection {
             traits::VtableImpl(ref impl_data) => {
                 let ac = tcx.impl_or_trait_items(impl_data.impl_def_id)
-                    .iter().filter_map(|id| {
-                        match *id {
-                            ty::ConstTraitItemId(def_id) => {
-                                Some(tcx.impl_or_trait_item(def_id))
-                            }
+                    .iter().filter_map(|&def_id| {
+                        match tcx.impl_or_trait_item(def_id) {
+                            ty::ConstTraitItem(ic) => Some(ic),
                             _ => None
                         }
-                    }).find(|ic| ic.name() == ti.name);
+                    }).find(|ic| ic.name == ti.name);
                 match ac {
-                    Some(ic) => lookup_const_by_id(tcx, ic.def_id(), None),
+                    Some(ic) => lookup_const_by_id(tcx, ic.def_id, None),
                     None => match ti.node {
                         hir::ConstTraitItem(ref ty, Some(ref expr)) => {
                             Some((&*expr, tcx.ast_ty_to_prim_ty(ty)))
index 94581a3fc89768f6ba02ac695c13c12f391eacb0..6df8c7de415a0c91c3afecdd6ab2dbd809873d62 100644 (file)
@@ -166,9 +166,6 @@ pub enum Family {
 
 pub const tag_unsafety: usize = 0x9a;
 
-pub const tag_associated_type_names: usize = 0x9b;
-pub const tag_associated_type_name: usize = 0x9c;
-
 pub const tag_polarity: usize = 0x9d;
 
 pub const tag_macro_defs: usize = 0x10e; // top-level only
index 38b18fa63e3eb40ff0703e56d36974ecf232362b..c4ce7af269daabb6878db36cbdd4a8d4b8d1fa04 100644 (file)
@@ -179,10 +179,15 @@ fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>
         result
     }
 
-    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId> {
+    fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId> {
         self.dep_graph.read(DepNode::MetaData(def_id));
-        let cdata = self.get_crate_data(def_id.krate);
-        decoder::get_impl_or_trait_items(&cdata, def_id.index)
+        let mut result = vec![];
+        let crate_data = self.get_crate_data(def_id.krate);
+        let get_crate_data = |cnum| self.get_crate_data(cnum);
+        decoder::each_child_of_item(&crate_data, def_id.index, get_crate_data, |def, _, _| {
+            result.push(def.def_id());
+        });
+        result
     }
 
     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity
index 507e6414181b81bedeecde01cdd7ea21b1f58c9d..8b87f0e718fb2dcbeb27470a64508d9810c88ae5 100644 (file)
@@ -453,10 +453,6 @@ fn item_to_def(cdata: Cmd, item: rbml::Doc, did: DefId) -> Option<Def> {
     })
 }
 
-fn parse_associated_type_names(item_doc: rbml::Doc) -> Vec<ast::Name> {
-    item_doc.get(tag_associated_type_names).decoder().decode()
-}
-
 pub fn get_trait_def<'a, 'tcx>(cdata: Cmd,
                                item_id: DefIndex,
                                tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::TraitDef<'tcx>
@@ -464,16 +460,11 @@ pub fn get_trait_def<'a, 'tcx>(cdata: Cmd,
     let item_doc = cdata.lookup_item(item_id);
     let generics = doc_generics(item_doc, tcx, cdata);
     let unsafety = item_doc.get(tag_unsafety).decoder().decode();
-    let associated_type_names = parse_associated_type_names(item_doc);
     let paren_sugar = item_doc.get(tag_paren_sugar).decoder().decode();
     let trait_ref = doc_trait_ref(item_doc.get(tag_item_trait_ref), tcx, cdata);
     let def_path = def_path(cdata, item_id).unwrap();
 
-    ty::TraitDef::new(unsafety,
-                      paren_sugar,
-                      generics,
-                      trait_ref,
-                      associated_type_names,
+    ty::TraitDef::new(unsafety, paren_sugar, generics, trait_ref,
                       def_path.deterministic_hash(tcx))
 }
 
@@ -855,22 +846,6 @@ fn get_explicit_self<'a, 'tcx>(cdata: Cmd, item: rbml::Doc, tcx: TyCtxt<'a, 'tcx
     dcx.decode()
 }
 
-/// Returns the def IDs of all the items in the given implementation.
-pub fn get_impl_or_trait_items(cdata: Cmd, impl_id: DefIndex)
-                               -> Vec<ty::ImplOrTraitItemId> {
-    let item = cdata.lookup_item(impl_id);
-    let mut dcx = item.get(tag_mod_children).decoder();
-    dcx.cdata = Some(cdata);
-    dcx.seq().map(|def_id: DefId| {
-        match item_to_def(cdata, cdata.lookup_item(def_id.index), def_id) {
-            Some(Def::AssociatedConst(def_id)) => ty::ConstTraitItemId(def_id),
-            Some(Def::Method(def_id)) => ty::MethodTraitItemId(def_id),
-            Some(Def::AssociatedTy(_, def_id)) => ty::TypeTraitItemId(def_id),
-            def => bug!("get_impl_or_trait_items: invalid def {:?}", def)
-        }
-    }).collect()
-}
-
 pub fn get_trait_name(cdata: Cmd, id: DefIndex) -> ast::Name {
     let doc = cdata.lookup_item(id);
     item_name(doc)
index 7b4a6972d221be6241c52074d922db396b68ca89..326eb0fe9a3ab7cff13870aba728b072545c9cd1 100644 (file)
@@ -993,8 +993,7 @@ fn encode_info_for_item(&mut self,
                 }
 
                 self.start_tag(tag_mod_children);
-                let items = tcx.impl_or_trait_items(def_id);
-                self.seq(&items[..], |_, id| id.def_id());
+                tcx.impl_or_trait_items(def_id).encode(self).unwrap();
                 <[def::Export]>::encode(&[], self).unwrap();
                 self.end_tag();
 
@@ -1039,7 +1038,6 @@ fn encode_info_for_item(&mut self,
                 tcx.trait_has_default_impl(def_id).encode(self).unwrap();
                 self.end_tag();
 
-                encode_associated_type_names(self, &trait_def.associated_type_names);
                 self.encode_generics(&trait_def.generics, &trait_predicates);
                 self.encode_predicates(&tcx.lookup_super_predicates(def_id),
                                        tag_item_super_predicates);
@@ -1051,8 +1049,7 @@ fn encode_info_for_item(&mut self,
                 encode_deprecation(self, depr);
 
                 self.start_tag(tag_mod_children);
-                let items = tcx.impl_or_trait_items(def_id);
-                self.seq(&items[..], |_, id| id.def_id());
+                tcx.impl_or_trait_items(def_id).encode(self).unwrap();
                 <[def::Export]>::encode(&[], self).unwrap();
                 self.end_tag();
 
@@ -1151,7 +1148,6 @@ fn encode_addl_impl_info(&mut self,
                 None
             };
 
-            let trait_item_def_id = trait_item_def_id.def_id();
             self.record(trait_item_def_id,
                         EncodeContext::encode_info_for_impl_item,
                         (impl_id, trait_item_def_id, ast_item));
@@ -1163,8 +1159,7 @@ fn encode_addl_trait_info(&mut self,
                               trait_items: &[hir::TraitItem]) {
         // Now output the trait item info for each trait item.
         let r = self.tcx.impl_or_trait_items(def_id);
-        for (item_def_id, trait_item) in r.iter().zip(trait_items) {
-            let item_def_id = item_def_id.def_id();
+        for (&item_def_id, trait_item) in r.iter().zip(trait_items) {
             assert!(item_def_id.is_local());
             self.record(item_def_id,
                         EncodeContext::encode_info_for_trait_item,
@@ -1331,12 +1326,6 @@ fn encode_attributes(ecx: &mut EncodeContext, attrs: &[ast::Attribute]) {
     ecx.end_tag();
 }
 
-fn encode_associated_type_names(ecx: &mut EncodeContext, names: &[Name]) {
-    ecx.start_tag(tag_associated_type_names);
-    names.encode(ecx).unwrap();
-    ecx.end_tag();
-}
-
 fn encode_crate_deps(ecx: &mut EncodeContext, cstore: &cstore::CStore) {
     fn get_ordered_deps(cstore: &cstore::CStore)
                         -> Vec<(CrateNum, Rc<cstore::CrateMetadata>)> {
index 3df3a2decba3ba0dd6edf89c6d2a08ebc9d793a9..7264dcea9553e75c8816123aa50d9120870ad691 100644 (file)
@@ -432,9 +432,9 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>, chi
                 // info.
 
                 let trait_item_def_ids = self.session.cstore.impl_or_trait_items(def_id);
-                for trait_item_def in &trait_item_def_ids {
+                for &trait_item_def in &trait_item_def_ids {
                     let trait_item_name =
-                        self.session.cstore.item_name(trait_item_def.def_id());
+                        self.session.cstore.item_name(trait_item_def);
 
                     debug!("(building reduced graph for external crate) ... adding trait item \
                             '{}'",
index 186183a8ad4d4f37765ca008e833d4b1e0e74bc2..aa68a873120ec8670db7ed78c17699c0ad84e02f 100644 (file)
@@ -374,8 +374,7 @@ pub fn get_method_data(&self, id: ast::NodeId,
         let qualname = format!("{}::{}", qualname, name);
 
         let def_id = self.tcx.map.local_def_id(id);
-        let decl_id = self.tcx.trait_item_of_item(def_id).and_then(|new_id| {
-            let new_def_id = new_id.def_id();
+        let decl_id = self.tcx.trait_item_of_item(def_id).and_then(|new_def_id| {
             if new_def_id != def_id {
                 Some(new_def_id)
             } else {
@@ -543,14 +542,9 @@ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
                                 .map(|mr| mr.def_id())
                         }
                         ty::ImplContainer(def_id) => {
-                            let impl_items = self.tcx.impl_or_trait_items(def_id);
-                            Some(impl_items.iter()
-                                           .find(|mr| {
-                                               self.tcx.impl_or_trait_item(mr.def_id()).name() ==
-                                               ti.name()
-                                           })
-                                           .unwrap()
-                                           .def_id())
+                            Some(*self.tcx.impl_or_trait_items(def_id).iter().find(|&&mr| {
+                                self.tcx.impl_or_trait_item(mr).name() == ti.name()
+                            }).unwrap())
                         }
                     }
                 } else {
index 9db5020747e1f39619a2c49db9eb733955007dfb..8540c7a99db15a466c9102091fb3a15d6ac0a94a 100644 (file)
@@ -235,24 +235,20 @@ pub fn get_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         .iter()
 
         // Filter out non-method items.
-        .filter_map(|item_def_id| {
-            match *item_def_id {
-                ty::MethodTraitItemId(def_id) => Some(def_id),
-                _ => None,
+        .filter_map(|&item_def_id| {
+            match tcx.impl_or_trait_item(item_def_id) {
+                ty::MethodTraitItem(m) => Some(m),
+                _ => None
             }
         })
 
         // Now produce pointers for each remaining method. If the
         // method could never be called from this object, just supply
         // null.
-        .map(|trait_method_def_id| {
+        .map(|trait_method_type| {
             debug!("get_vtable_methods: trait_method_def_id={:?}",
-                   trait_method_def_id);
+                   trait_method_type.def_id);
 
-            let trait_method_type = match tcx.impl_or_trait_item(trait_method_def_id) {
-                ty::MethodTraitItem(m) => m,
-                _ => bug!("should be a method, not other assoc item"),
-            };
             let name = trait_method_type.name;
 
             // Some methods cannot be called on an object; skip those.
@@ -266,7 +262,7 @@ pub fn get_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
             // the method may have some early-bound lifetimes, add
             // regions for those
-            let method_substs = Substs::for_item(tcx, trait_method_def_id,
+            let method_substs = Substs::for_item(tcx, trait_method_type.def_id,
                                                  |_, _| tcx.mk_region(ty::ReErased),
                                                  |_, _| tcx.types.err);
 
index 999433db2407182d22204d96adbb6aa29b209c05..cad5ed4f2e651e1363d463c2c695a2a11c12adf8 100644 (file)
@@ -248,16 +248,14 @@ fn trans_def(ccx: &'a CrateContext<'a, 'tcx>,
             if let traits::VtableImpl(vtable_impl) = vtable {
                 let name = ccx.tcx().item_name(instance.def);
                 let ac = ccx.tcx().impl_or_trait_items(vtable_impl.impl_def_id)
-                    .iter().filter_map(|id| {
-                        match *id {
-                            ty::ConstTraitItemId(def_id) => {
-                                Some(ccx.tcx().impl_or_trait_item(def_id))
-                            }
+                    .iter().filter_map(|&def_id| {
+                        match ccx.tcx().impl_or_trait_item(def_id) {
+                            ty::ConstTraitItem(ac) => Some(ac),
                             _ => None
                         }
-                    }).find(|ic| ic.name() == name);
+                    }).find(|ic| ic.name == name);
                 if let Some(ac) = ac {
-                    instance = Instance::new(ac.def_id(), vtable_impl.substs);
+                    instance = Instance::new(ac.def_id, vtable_impl.substs);
                 }
             }
         }
index 675c863a3bf0602324bcec63e515c19a7a7ac6d3..00c9ea3af182e2aaa2d089bf26e58ac633d804ec 100644 (file)
@@ -1134,16 +1134,23 @@ fn trait_path_to_object_type(&self,
             return tcx.types.err;
         }
 
-        let mut associated_types: FnvHashSet<(DefId, ast::Name)> =
-            traits::supertraits(tcx, principal)
-            .flat_map(|tr| {
-                let trait_def = tcx.lookup_trait_def(tr.def_id());
-                trait_def.associated_type_names
-                    .clone()
-                    .into_iter()
-                    .map(move |associated_type_name| (tr.def_id(), associated_type_name))
-            })
-            .collect();
+        let mut associated_types = FnvHashSet::default();
+        for tr in traits::supertraits(tcx, principal) {
+            if let Some(trait_id) = tcx.map.as_local_node_id(tr.def_id()) {
+                use collect::trait_associated_type_names;
+
+                associated_types.extend(trait_associated_type_names(tcx, trait_id)
+                    .map(|name| (tr.def_id(), name)))
+            } else {
+                let trait_items = tcx.impl_or_trait_items(tr.def_id());
+                associated_types.extend(trait_items.iter().filter_map(|&def_id| {
+                    match tcx.impl_or_trait_item(def_id) {
+                        ty::TypeTraitItem(ref item) => Some(item.name),
+                        _ => None
+                    }
+                }).map(|name| (tr.def_id(), name)));
+            }
+        }
 
         for projection_bound in &projection_bounds {
             let pair = (projection_bound.0.projection_ty.trait_ref.def_id,
index 71219d82668e4f4822ceb2eec27e9ee5f93a06e5..73caf79c9f8d1b345c92870a239cad79fa0dd141 100644 (file)
@@ -368,7 +368,7 @@ pub fn impl_or_trait_item(&self,
     {
         self.tcx.impl_or_trait_items(def_id)
             .iter()
-            .map(|&did| self.tcx.impl_or_trait_item(did.def_id()))
+            .map(|&did| self.tcx.impl_or_trait_item(did))
             .find(|m| m.name() == item_name)
     }
 }
index 8d9fd523a8f5280d16408c509c5d48d6ff2618cd..3a854da1d48022e9e42372d32c1d5f72a9dec091 100644 (file)
@@ -1348,8 +1348,12 @@ fn trait_defines_associated_type_named(&self,
                                            assoc_name: ast::Name)
                                            -> bool
     {
-        let trait_def = self.tcx().lookup_trait_def(trait_def_id);
-        trait_def.associated_type_names.contains(&assoc_name)
+        self.tcx().impl_or_trait_items(trait_def_id).iter().any(|&def_id| {
+            match self.tcx().impl_or_trait_item(def_id) {
+                ty::TypeTraitItem(ref item) => item.name == assoc_name,
+                _ => false
+            }
+        })
     }
 
     fn ty_infer(&self, _span: Span) -> Ty<'tcx> {
index fb077d279c99875b84e54fda5d99fec2d5ed9310..3b4c98fc71e4451246ff6286df5a3ea82ba6ed35 100644 (file)
@@ -20,8 +20,7 @@
 use rustc::ty::subst::Subst;
 use rustc::ty::{self, TyCtxt, TypeFoldable};
 use rustc::traits::{self, Reveal};
-use rustc::ty::{ImplOrTraitItemId, ConstTraitItemId};
-use rustc::ty::{MethodTraitItemId, TypeTraitItemId, ParameterEnvironment};
+use rustc::ty::{ParameterEnvironment};
 use rustc::ty::{Ty, TyBool, TyChar, TyError};
 use rustc::ty::{TyParam, TyRawPtr};
 use rustc::ty::{TyRef, TyAdt, TyTrait, TyNever, TyTuple};
@@ -158,7 +157,7 @@ fn check_implementation(&self, item: &Item) {
             }
         }
 
-        tcx.impl_or_trait_item_ids.borrow_mut().insert(impl_did, Rc::new(impl_items));
+        tcx.impl_or_trait_item_def_ids.borrow_mut().insert(impl_did, Rc::new(impl_items));
     }
 
     fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
@@ -174,22 +173,11 @@ fn add_trait_impl(&self, impl_trait_ref: ty::TraitRef<'gcx>, impl_def_id: DefId)
     }
 
     // Converts an implementation in the AST to a vector of items.
-    fn create_impl_from_item(&self, item: &Item) -> Vec<ImplOrTraitItemId> {
+    fn create_impl_from_item(&self, item: &Item) -> Vec<DefId> {
         match item.node {
             ItemImpl(.., ref impl_items) => {
                 impl_items.iter().map(|impl_item| {
-                    let impl_def_id = self.crate_context.tcx.map.local_def_id(impl_item.id);
-                    match impl_item.node {
-                        hir::ImplItemKind::Const(..) => {
-                            ConstTraitItemId(impl_def_id)
-                        }
-                        hir::ImplItemKind::Method(..) => {
-                            MethodTraitItemId(impl_def_id)
-                        }
-                        hir::ImplItemKind::Type(_) => {
-                            TypeTraitItemId(impl_def_id)
-                        }
-                    }
+                    self.crate_context.tcx.map.local_def_id(impl_item.id)
                 }).collect()
             }
             _ => {
@@ -210,7 +198,7 @@ fn populate_destructors(&self) {
         tcx.populate_implementations_for_trait_if_necessary(drop_trait);
         let drop_trait = tcx.lookup_trait_def(drop_trait);
 
-        let impl_items = tcx.impl_or_trait_item_ids.borrow();
+        let impl_items = tcx.impl_or_trait_item_def_ids.borrow();
 
         drop_trait.for_each_impl(tcx, |impl_did| {
             let items = impl_items.get(&impl_did).unwrap();
@@ -223,7 +211,7 @@ fn populate_destructors(&self) {
             let self_type = tcx.lookup_item_type(impl_did);
             match self_type.ty.sty {
                 ty::TyAdt(type_def, _) => {
-                    type_def.set_destructor(method_def_id.def_id());
+                    type_def.set_destructor(method_def_id);
                 }
                 _ => {
                     // Destructors only work on nominal types.
index 9d072491cc28b532871b54723f54dcb55150fa08..c42b8f8840028afecb8fdc41764c3dff85899744 100644 (file)
@@ -44,29 +44,29 @@ fn check_for_common_items_in_impls(&self, impl1: DefId, impl2: DefId) {
         enum Namespace { Type, Value }
 
         fn name_and_namespace<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                                        item: &ty::ImplOrTraitItemId)
+                                        def_id: DefId)
                                         -> (ast::Name, Namespace)
         {
-            let name = tcx.impl_or_trait_item(item.def_id()).name();
-            (name, match *item {
-                ty::TypeTraitItemId(..) => Namespace::Type,
-                ty::ConstTraitItemId(..) => Namespace::Value,
-                ty::MethodTraitItemId(..) => Namespace::Value,
+            let item = tcx.impl_or_trait_item(def_id);
+            (item.name(), match item {
+                ty::TypeTraitItem(..) => Namespace::Type,
+                ty::ConstTraitItem(..) => Namespace::Value,
+                ty::MethodTraitItem(..) => Namespace::Value,
             })
         }
 
-        let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
+        let impl_items = self.tcx.impl_or_trait_item_def_ids.borrow();
 
-        for item1 in &impl_items[&impl1][..] {
+        for &item1 in &impl_items[&impl1][..] {
             let (name, namespace) = name_and_namespace(self.tcx, item1);
 
-            for item2 in &impl_items[&impl2][..] {
+            for &item2 in &impl_items[&impl2][..] {
                 if (name, namespace) == name_and_namespace(self.tcx, item2) {
                     let msg = format!("duplicate definitions with name `{}`", name);
-                    let node_id = self.tcx.map.as_local_node_id(item1.def_id()).unwrap();
+                    let node_id = self.tcx.map.as_local_node_id(item1).unwrap();
                     self.tcx.sess.add_lint(lint::builtin::OVERLAPPING_INHERENT_IMPLS,
                                            node_id,
-                                           self.tcx.span_of_impl(item1.def_id()).unwrap(),
+                                           self.tcx.span_of_impl(item1).unwrap(),
                                            msg);
                 }
             }
index fa052bec7be3d6f1eab92d9e221feb62b432b815..d67dcbb4baf0d48e90651531e951d58ed1c289e8 100644 (file)
@@ -361,10 +361,15 @@ fn trait_defines_associated_type_named(&self,
                                            -> bool
     {
         if let Some(trait_id) = self.tcx().map.as_local_node_id(trait_def_id) {
-            trait_defines_associated_type_named(self.ccx, trait_id, assoc_name)
+            trait_associated_type_names(self.tcx(), trait_id)
+                .any(|name| name == assoc_name)
         } else {
-            let trait_def = self.tcx().lookup_trait_def(trait_def_id);
-            trait_def.associated_type_names.contains(&assoc_name)
+            self.tcx().impl_or_trait_items(trait_def_id).iter().any(|&def_id| {
+                match self.tcx().impl_or_trait_item(def_id) {
+                    ty::TypeTraitItem(ref item) => item.name == assoc_name,
+                    _ => false
+                }
+            })
         }
     }
 
@@ -926,15 +931,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
 
             // Add an entry mapping
             let trait_item_def_ids = Rc::new(trait_items.iter().map(|trait_item| {
-                let def_id = ccx.tcx.map.local_def_id(trait_item.id);
-                match trait_item.node {
-                    hir::ConstTraitItem(..) => ty::ConstTraitItemId(def_id),
-                    hir::MethodTraitItem(..) => ty::MethodTraitItemId(def_id),
-                    hir::TypeTraitItem(..) => ty::TypeTraitItemId(def_id)
-                }
+                ccx.tcx.map.local_def_id(trait_item.id)
             }).collect());
-            tcx.impl_or_trait_item_ids.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id),
-                                                           trait_item_def_ids);
+            tcx.impl_or_trait_item_def_ids.borrow_mut().insert(ccx.tcx.map.local_def_id(it.id),
+                                                               trait_item_def_ids);
         },
         hir::ItemStruct(ref struct_def, _) |
         hir::ItemUnion(ref struct_def, _) => {
@@ -1266,9 +1266,9 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
         return def.clone();
     }
 
-    let (unsafety, generics, items) = match it.node {
-        hir::ItemTrait(unsafety, ref generics, _, ref items) => {
-            (unsafety, generics, items)
+    let (unsafety, generics) = match it.node {
+        hir::ItemTrait(unsafety, ref generics, _, _) => {
+            (unsafety, generics)
         }
         _ => span_bug!(it.span, "trait_def_of_item invoked on non-trait"),
     };
@@ -1288,32 +1288,20 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     let ty_generics = generics_of_def_id(ccx, def_id);
     let substs = mk_item_substs(&ccx.icx(generics), it.span, def_id);
 
-    let associated_type_names: Vec<_> = items.iter().filter_map(|trait_item| {
-        match trait_item.node {
-            hir::TypeTraitItem(..) => Some(trait_item.name),
-            _ => None,
-        }
-    }).collect();
-
     let def_path_hash = tcx.def_path(def_id).deterministic_hash(tcx);
 
     let trait_ref = ty::TraitRef::new(def_id, substs);
-    let trait_def = ty::TraitDef::new(unsafety,
-                                      paren_sugar,
-                                      ty_generics,
-                                      trait_ref,
-                                      associated_type_names,
+    let trait_def = ty::TraitDef::new(unsafety, paren_sugar, ty_generics, trait_ref,
                                       def_path_hash);
 
     tcx.intern_trait_def(trait_def)
 }
 
-fn trait_defines_associated_type_named(ccx: &CrateCtxt,
-                                       trait_node_id: ast::NodeId,
-                                       assoc_name: ast::Name)
-                                       -> bool
+pub fn trait_associated_type_names<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
+                                                   trait_node_id: ast::NodeId)
+                                                   -> impl Iterator<Item=ast::Name> + 'a
 {
-    let item = match ccx.tcx.map.get(trait_node_id) {
+    let item = match tcx.map.get(trait_node_id) {
         hir_map::NodeItem(item) => item,
         _ => bug!("trait_node_id {} is not an item", trait_node_id)
     };
@@ -1323,10 +1311,10 @@ fn trait_defines_associated_type_named(ccx: &CrateCtxt,
         _ => bug!("trait_node_id {} is not a trait", trait_node_id)
     };
 
-    trait_items.iter().any(|trait_item| {
+    trait_items.iter().filter_map(|trait_item| {
         match trait_item.node {
-            hir::TypeTraitItem(..) => trait_item.name == assoc_name,
-            _ => false,
+            hir::TypeTraitItem(..) => Some(trait_item.name),
+            _ => None,
         }
     })
 }
index d2e2d578fcedbae8821ba3649a7775e070b88778..1f34cee5143c61e9e147bd4584efbaa3bfb121f1 100644 (file)
@@ -76,6 +76,7 @@
 
 #![feature(box_patterns)]
 #![feature(box_syntax)]
+#![feature(conservative_impl_trait)]
 #![feature(dotdot_in_tuple_patterns)]
 #![feature(quote)]
 #![feature(rustc_diagnostic_macros)]
index e992861b77bc6c29df444e4e32c15622f1068033..e72ea60072e0892f06071d08ac73d91005629c6c 100644 (file)
@@ -368,10 +368,8 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
     let predicates = tcx.lookup_predicates(did);
     let trait_items = tcx.sess.cstore.impl_or_trait_items(did)
             .iter()
-            .filter_map(|did| {
-        let did = did.def_id();
-        let impl_item = tcx.impl_or_trait_item(did);
-        match impl_item {
+            .filter_map(|&did| {
+        match tcx.impl_or_trait_item(did) {
             ty::ConstTraitItem(ref assoc_const) => {
                 let did = assoc_const.def_id;
                 let type_scheme = tcx.lookup_item_type(did);