diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 41f91a1d2ac..292f1eb1366 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -747,21 +747,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { trait_ref: &'l Option, typ: &'l ast::Ty, impl_items: &'l [ast::ImplItem]) { - let mut has_self_ref = false; if let Some(impl_data) = self.save_ctxt.get_item_data(item) { down_cast_data!(impl_data, ImplData, item.span); - if let Some(ref self_ref) = impl_data.self_ref { - has_self_ref = true; - if !self.span.filter_generated(Some(self_ref.span), item.span) { - self.dumper.type_ref(self_ref.clone().lower(self.tcx)); - } - } - if let Some(ref trait_ref_data) = impl_data.trait_ref { - if !self.span.filter_generated(Some(trait_ref_data.span), item.span) { - self.dumper.type_ref(trait_ref_data.clone().lower(self.tcx)); - } - } - if !self.span.filter_generated(Some(impl_data.span), item.span) { self.dumper.impl_data(ImplData { id: impl_data.id, @@ -772,9 +759,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { }.lower(self.tcx)); } } - if !has_self_ref { - self.visit_ty(&typ); - } + self.visit_ty(&typ); if let &Some(ref trait_ref) = trait_ref { self.process_path(trait_ref.ref_id, &trait_ref.path, Some(recorder::TypeRef)); } diff --git a/src/librustc_save_analysis/json_api_dumper.rs b/src/librustc_save_analysis/json_api_dumper.rs index 342c33af2f8..277535f9e65 100644 --- a/src/librustc_save_analysis/json_api_dumper.rs +++ b/src/librustc_save_analysis/json_api_dumper.rs @@ -74,6 +74,15 @@ impl<'b, W: Write + 'b> Dump for JsonApiDumper<'b, W> { impl_fn!(mod_data, ModData, defs); impl_fn!(typedef, TypeDefData, defs); impl_fn!(variable, VariableData, defs); + + fn impl_data(&mut self, data: ImplData) { + if data.self_ref.is_some() { + self.result.relations.push(From::from(data)); + } + } + fn inheritance(&mut self, data: InheritanceData) { + self.result.relations.push(From::from(data)); + } } // FIXME methods. The defs have information about possible overriding and the @@ -87,6 +96,7 @@ struct Analysis { prelude: Option, imports: Vec, defs: Vec, + relations: Vec, // These two fields are dummies so that clients can parse the two kinds of // JSON data in the same way. refs: Vec<()>, @@ -100,6 +110,7 @@ impl Analysis { prelude: None, imports: vec![], defs: vec![], + relations: vec![], refs: vec![], macro_refs: vec![], } @@ -427,6 +438,42 @@ impl From for Option { } } +#[derive(Debug, RustcEncodable)] +struct Relation { + span: SpanData, + kind: RelationKind, + from: Id, + to: Id, +} + +#[derive(Debug, RustcEncodable)] +enum RelationKind { + Impl, + SuperTrait, +} + +impl From for Relation { + fn from(data: ImplData) -> Relation { + Relation { + span: data.span, + kind: RelationKind::Impl, + from: From::from(data.self_ref.unwrap_or(null_def_id())), + to: From::from(data.trait_ref.unwrap_or(null_def_id())), + } + } +} + +impl From for Relation { + fn from(data: InheritanceData) -> Relation { + Relation { + span: data.span, + kind: RelationKind::SuperTrait, + from: From::from(data.base_id), + to: From::from(data.deriv_id), + } + } +} + #[derive(Debug, RustcEncodable)] pub struct JsonSignature { span: SpanData, diff --git a/src/librustc_save_analysis/json_dumper.rs b/src/librustc_save_analysis/json_dumper.rs index 16c06a556df..09752994290 100644 --- a/src/librustc_save_analysis/json_dumper.rs +++ b/src/librustc_save_analysis/json_dumper.rs @@ -112,9 +112,14 @@ impl<'b, W: Write + 'b> Dump for JsonDumper<'b, W> { self.result.defs.push(def); } - // FIXME store this instead of throwing it away. - fn impl_data(&mut self, _data: ImplData) {} - fn inheritance(&mut self, _data: InheritanceData) {} + fn impl_data(&mut self, data: ImplData) { + if data.self_ref.is_some() { + self.result.relations.push(From::from(data)); + } + } + fn inheritance(&mut self, data: InheritanceData) { + self.result.relations.push(From::from(data)); + } } // FIXME do we want to change ExternalData to this mode? It will break DXR. @@ -131,6 +136,7 @@ struct Analysis { defs: Vec, refs: Vec, macro_refs: Vec, + relations: Vec, } impl Analysis { @@ -142,6 +148,7 @@ impl Analysis { defs: vec![], refs: vec![], macro_refs: vec![], + relations: vec![], } } } @@ -508,6 +515,42 @@ impl From for MacroRef { } } +#[derive(Debug, RustcEncodable)] +struct Relation { + span: SpanData, + kind: RelationKind, + from: Id, + to: Id, +} + +#[derive(Debug, RustcEncodable)] +enum RelationKind { + Impl, + SuperTrait, +} + +impl From for Relation { + fn from(data: ImplData) -> Relation { + Relation { + span: data.span, + kind: RelationKind::Impl, + from: From::from(data.self_ref.unwrap_or(null_def_id())), + to: From::from(data.trait_ref.unwrap_or(null_def_id())), + } + } +} + +impl From for Relation { + fn from(data: InheritanceData) -> Relation { + Relation { + span: data.span, + kind: RelationKind::SuperTrait, + from: From::from(data.base_id), + to: From::from(data.deriv_id), + } + } +} + #[derive(Debug, RustcEncodable)] pub struct JsonSignature { span: SpanData, diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index ebb33a12c87..ddc60fe5f81 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -239,7 +239,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { match typ.node { // Common case impl for a struct or something basic. ast::TyKind::Path(None, ref path) => { - filter!(self.span_utils, None, path.span, None); + if generated_code(path.span) { + return None; + } sub_span = self.span_utils.sub_span_for_type_name(path.span); type_data = self.lookup_ref_id(typ.id).map(|id| { TypeRefData {