diff options
| author | bors <bors@rust-lang.org> | 2015-01-16 06:31:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-16 06:31:02 +0000 |
| commit | 317da0bf2a868e0b946b78268d7b2414b865c2a9 (patch) | |
| tree | 1807914b71867e15c7e10afc0885077630bb0427 | |
| parent | b565501ad8b4e371e0aca0069c3f4781bd209254 (diff) | |
| parent | 33fd10d5e0bac969b522b0a9b1bcc1518d1554b2 (diff) | |
| download | rust-317da0bf2a868e0b946b78268d7b2414b865c2a9.tar.gz rust-317da0bf2a868e0b946b78268d7b2414b865c2a9.zip | |
Merge pull request #21181 from nick29581/save-fix
Two minor fixes for save-analysis Reviewed-by: huonw
| -rw-r--r-- | src/librustc_trans/save/mod.rs | 37 | ||||
| -rw-r--r-- | src/librustc_trans/save/recorder.rs | 18 |
2 files changed, 36 insertions, 19 deletions
diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index f2a67029170..b12903c814c 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -278,7 +278,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { // The qualname for a method is the trait name or name of the struct in an impl in // which the method is declared in followed by the method's name. let mut qualname = match ty::impl_of_method(&self.analysis.ty_cx, - ast_util::local_def(method.id)) { + ast_util::local_def(method.id)) { Some(impl_id) => match self.analysis.ty_cx.map.get(impl_id.node) { NodeItem(item) => { scope_id = item.id; @@ -349,7 +349,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { .and_then(|def_id| { if match def_id { ty::MethodTraitItemId(def_id) => { - method.id != 0 && def_id.node == 0 + def_id.node != 0 && def_id != ast_util::local_def(method.id) } ty::TypeTraitItemId(_) => false, } { @@ -392,8 +392,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { } 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 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { 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 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { 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 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { 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 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { 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 { diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index 11f8fbbaf11..eefaeca8306 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -19,6 +19,8 @@ use syntax::ast; 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 @@ impl<'a> FmtStrs<'a> { 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 @@ impl<'a> FmtStrs<'a> { 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, |
