Skip to content

Two minor fixes for save-analysis #21181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
} {
Expand Down Expand Up @@ -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);
Expand All @@ -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 => ()
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 => (),
}

Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions src/librustc_trans/save/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down