]> git.lizzy.rs Git - rust.git/commitdiff
Tweek save-analysis treatment of impls
authorNick Cameron <ncameron@mozilla.com>
Wed, 14 Jan 2015 09:24:09 +0000 (22:24 +1300)
committerNick Cameron <ncameron@mozilla.com>
Wed, 14 Jan 2015 09:24:09 +0000 (22:24 +1300)
src/librustc_trans/save/mod.rs
src/librustc_trans/save/recorder.rs

index 1bd8e01817485732cf82ad4106c17b97b8c70901..2cfe7940bbb585886088568d562ccb586619adde 100644 (file)
@@ -392,8 +392,7 @@ fn process_method(&mut self, method: &ast::Method) {
     }
 
     fn process_trait_ref(&mut self,
-                         trait_ref: &ast::TraitRef,
-                         impl_id: Option<NodeId>) {
+                         trait_ref: &ast::TraitRef) {
         match self.lookup_type_ref(trait_ref.ref_id) {
             Some(id) => {
                 let sub_span = self.span.sub_span_for_type_name(trait_ref.path.span);
@@ -402,14 +401,6 @@ fn process_trait_ref(&mut self,
                                  sub_span,
                                  id,
                                  self.cur_scope);
-                match impl_id {
-                    Some(impl_id) => self.fmt.impl_str(trait_ref.path.span,
-                                                       sub_span,
-                                                       impl_id,
-                                                       id,
-                                                       self.cur_scope),
-                    None => (),
-                }
                 visit::walk_path(self, &trait_ref.path);
             },
             None => ()
@@ -652,7 +643,9 @@ fn process_impl(&mut self,
                     trait_ref: &Option<ast::TraitRef>,
                     typ: &ast::Ty,
                     impl_items: &Vec<ast::ImplItem>) {
+        let trait_id = trait_ref.as_ref().and_then(|tr| self.lookup_type_ref(tr.ref_id));
         match typ.node {
+            // Common case impl for a struct or something basic.
             ast::TyPath(ref path, id) => {
                 match self.lookup_type_ref(id) {
                     Some(id) => {
@@ -665,17 +658,29 @@ fn process_impl(&mut self,
                         self.fmt.impl_str(path.span,
                                           sub_span,
                                           item.id,
-                                          id,
+                                          Some(id),
+                                          trait_id,
                                           self.cur_scope);
                     },
                     None => ()
                 }
             },
-            _ => self.visit_ty(&*typ),
+            _ => {
+                // Less useful case, impl for a compound type.
+                self.visit_ty(&*typ);
+
+                let sub_span = self.span.sub_span_for_type_name(typ.span);
+                self.fmt.impl_str(typ.span,
+                                  sub_span,
+                                  item.id,
+                                  None,
+                                  trait_id,
+                                  self.cur_scope);
+            }
         }
 
         match *trait_ref {
-            Some(ref trait_ref) => self.process_trait_ref(trait_ref, Some(item.id)),
+            Some(ref trait_ref) => self.process_trait_ref(trait_ref),
             None => (),
         }
 
@@ -1076,7 +1081,7 @@ fn visit_generics(&mut self, generics: &ast::Generics) {
         for param in generics.ty_params.iter() {
             for bound in param.bounds.iter() {
                 if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
-                    self.process_trait_ref(&trait_ref.trait_ref, None);
+                    self.process_trait_ref(&trait_ref.trait_ref);
                 }
             }
             if let Some(ref ty) = param.default {
index 23598751c08d73c724f0947d6bd0c312bc361723..5cd3b9f20b620aebd6a517aa6192cf0721ec5f6d 100644 (file)
@@ -19,6 +19,8 @@
 use syntax::ast::{NodeId,DefId};
 use syntax::codemap::*;
 
+const ZERO_DEF_ID: DefId = DefId { node: 0, krate: 0 };
+
 pub struct Recorder {
     // output file
     pub out: Box<Writer+'static>,
@@ -121,7 +123,9 @@ fn lookup_row(r: Row) -> (&'static str, Vec<&'static str>, bool, bool) {
             MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true),
             Struct => ("struct", vec!("id","ctor_id","qualname","scopeid","value"), true, true),
             Trait => ("trait", vec!("id","qualname","scopeid","value"), true, true),
-            Impl => ("impl", vec!("id","refid","refidcrate","scopeid"), true, true),
+            Impl => ("impl",
+                     vec!("id","refid","refidcrate","traitid","traitidcrate","scopeid"),
+                     true, true),
             Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false),
             UseAlias => ("use_alias",
                          vec!("id","refid","refidcrate","name","scopeid"),
@@ -444,12 +448,20 @@ pub fn impl_str(&mut self,
                     span: Span,
                     sub_span: Option<Span>,
                     id: NodeId,
-                    ref_id: DefId,
+                    ref_id: Option<DefId>,
+                    trait_id: Option<DefId>,
                     scope_id: NodeId) {
+        let ref_id = ref_id.unwrap_or(ZERO_DEF_ID);
+        let trait_id = trait_id.unwrap_or(ZERO_DEF_ID);
         self.check_and_record(Impl,
                               span,
                               sub_span,
-                              svec!(id, ref_id.node, ref_id.krate, scope_id));
+                              svec!(id,
+                                    ref_id.node,
+                                    ref_id.krate,
+                                    trait_id.node,
+                                    trait_id.krate,
+                                    scope_id));
     }
 
     pub fn mod_str(&mut self,