Skip to content

Commit 317da0b

Browse files
committed
Merge pull request #21181 from nick29581/save-fix
Two minor fixes for save-analysis Reviewed-by: huonw
2 parents b565501 + 33fd10d commit 317da0b

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/librustc_trans/save/mod.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
278278
// The qualname for a method is the trait name or name of the struct in an impl in
279279
// which the method is declared in followed by the method's name.
280280
let mut qualname = match ty::impl_of_method(&self.analysis.ty_cx,
281-
ast_util::local_def(method.id)) {
281+
ast_util::local_def(method.id)) {
282282
Some(impl_id) => match self.analysis.ty_cx.map.get(impl_id.node) {
283283
NodeItem(item) => {
284284
scope_id = item.id;
@@ -349,7 +349,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
349349
.and_then(|def_id| {
350350
if match def_id {
351351
ty::MethodTraitItemId(def_id) => {
352-
method.id != 0 && def_id.node == 0
352+
def_id.node != 0 && def_id != ast_util::local_def(method.id)
353353
}
354354
ty::TypeTraitItemId(_) => false,
355355
} {
@@ -392,8 +392,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
392392
}
393393

394394
fn process_trait_ref(&mut self,
395-
trait_ref: &ast::TraitRef,
396-
impl_id: Option<NodeId>) {
395+
trait_ref: &ast::TraitRef) {
397396
match self.lookup_type_ref(trait_ref.ref_id) {
398397
Some(id) => {
399398
let sub_span = self.span.sub_span_for_type_name(trait_ref.path.span);
@@ -402,14 +401,6 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
402401
sub_span,
403402
id,
404403
self.cur_scope);
405-
match impl_id {
406-
Some(impl_id) => self.fmt.impl_str(trait_ref.path.span,
407-
sub_span,
408-
impl_id,
409-
id,
410-
self.cur_scope),
411-
None => (),
412-
}
413404
visit::walk_path(self, &trait_ref.path);
414405
},
415406
None => ()
@@ -652,7 +643,9 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
652643
trait_ref: &Option<ast::TraitRef>,
653644
typ: &ast::Ty,
654645
impl_items: &Vec<ast::ImplItem>) {
646+
let trait_id = trait_ref.as_ref().and_then(|tr| self.lookup_type_ref(tr.ref_id));
655647
match typ.node {
648+
// Common case impl for a struct or something basic.
656649
ast::TyPath(ref path, id) => {
657650
match self.lookup_type_ref(id) {
658651
Some(id) => {
@@ -665,17 +658,29 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
665658
self.fmt.impl_str(path.span,
666659
sub_span,
667660
item.id,
668-
id,
661+
Some(id),
662+
trait_id,
669663
self.cur_scope);
670664
},
671665
None => ()
672666
}
673667
},
674-
_ => self.visit_ty(&*typ),
668+
_ => {
669+
// Less useful case, impl for a compound type.
670+
self.visit_ty(&*typ);
671+
672+
let sub_span = self.span.sub_span_for_type_name(typ.span);
673+
self.fmt.impl_str(typ.span,
674+
sub_span,
675+
item.id,
676+
None,
677+
trait_id,
678+
self.cur_scope);
679+
}
675680
}
676681

677682
match *trait_ref {
678-
Some(ref trait_ref) => self.process_trait_ref(trait_ref, Some(item.id)),
683+
Some(ref trait_ref) => self.process_trait_ref(trait_ref),
679684
None => (),
680685
}
681686

@@ -1076,7 +1081,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10761081
for param in generics.ty_params.iter() {
10771082
for bound in param.bounds.iter() {
10781083
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
1079-
self.process_trait_ref(&trait_ref.trait_ref, None);
1084+
self.process_trait_ref(&trait_ref.trait_ref);
10801085
}
10811086
}
10821087
if let Some(ref ty) = param.default {

src/librustc_trans/save/recorder.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use syntax::ast;
1919
use syntax::ast::{NodeId,DefId};
2020
use syntax::codemap::*;
2121

22+
const ZERO_DEF_ID: DefId = DefId { node: 0, krate: 0 };
23+
2224
pub struct Recorder {
2325
// output file
2426
pub out: Box<Writer+'static>,
@@ -121,7 +123,9 @@ impl<'a> FmtStrs<'a> {
121123
MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true),
122124
Struct => ("struct", vec!("id","ctor_id","qualname","scopeid","value"), true, true),
123125
Trait => ("trait", vec!("id","qualname","scopeid","value"), true, true),
124-
Impl => ("impl", vec!("id","refid","refidcrate","scopeid"), true, true),
126+
Impl => ("impl",
127+
vec!("id","refid","refidcrate","traitid","traitidcrate","scopeid"),
128+
true, true),
125129
Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false),
126130
UseAlias => ("use_alias",
127131
vec!("id","refid","refidcrate","name","scopeid"),
@@ -444,12 +448,20 @@ impl<'a> FmtStrs<'a> {
444448
span: Span,
445449
sub_span: Option<Span>,
446450
id: NodeId,
447-
ref_id: DefId,
451+
ref_id: Option<DefId>,
452+
trait_id: Option<DefId>,
448453
scope_id: NodeId) {
454+
let ref_id = ref_id.unwrap_or(ZERO_DEF_ID);
455+
let trait_id = trait_id.unwrap_or(ZERO_DEF_ID);
449456
self.check_and_record(Impl,
450457
span,
451458
sub_span,
452-
svec!(id, ref_id.node, ref_id.krate, scope_id));
459+
svec!(id,
460+
ref_id.node,
461+
ref_id.krate,
462+
trait_id.node,
463+
trait_id.krate,
464+
scope_id));
453465
}
454466

455467
pub fn mod_str(&mut self,

0 commit comments

Comments
 (0)