Skip to content
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

save-analysis: handle aliasing imports a bit more nicely #50399

Merged
merged 1 commit into from
May 15, 2018
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
54 changes: 46 additions & 8 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rustc_target = { path = "../librustc_target" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.15"
rls-data = "0.16"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
100 changes: 8 additions & 92 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,80 +268,6 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
}
}

fn process_def_kind(
&mut self,
ref_id: NodeId,
span: Span,
sub_span: Option<Span>,
def_id: DefId,
) {
if self.span.filter_generated(sub_span, span) {
return;
}

let def = self.save_ctxt.get_path_def(ref_id);
match def {
HirDef::Mod(_) => {
let span = self.span_from_span(sub_span.expect("No span found for mod ref"));
self.dumper.dump_ref(Ref {
kind: RefKind::Mod,
span,
ref_id: ::id_from_def_id(def_id),
});
}
HirDef::Struct(..) |
HirDef::Variant(..) |
HirDef::Union(..) |
HirDef::Enum(..) |
HirDef::TyAlias(..) |
HirDef::TyForeign(..) |
HirDef::TraitAlias(..) |
HirDef::Trait(_) => {
let span = self.span_from_span(sub_span.expect("No span found for type ref"));
self.dumper.dump_ref(Ref {
kind: RefKind::Type,
span,
ref_id: ::id_from_def_id(def_id),
});
}
HirDef::Static(..) |
HirDef::Const(..) |
HirDef::StructCtor(..) |
HirDef::VariantCtor(..) => {
let span = self.span_from_span(sub_span.expect("No span found for var ref"));
self.dumper.dump_ref(Ref {
kind: RefKind::Variable,
span,
ref_id: ::id_from_def_id(def_id),
});
}
HirDef::Fn(..) => {
let span = self.span_from_span(sub_span.expect("No span found for fn ref"));
self.dumper.dump_ref(Ref {
kind: RefKind::Function,
span,
ref_id: ::id_from_def_id(def_id),
});
}
// With macros 2.0, we can legitimately get a ref to a macro, but
// we don't handle it properly for now (FIXME).
HirDef::Macro(..) => {}
HirDef::Local(..) |
HirDef::Upvar(..) |
HirDef::SelfTy(..) |
HirDef::Label(_) |
HirDef::TyParam(..) |
HirDef::Method(..) |
HirDef::AssociatedTy(..) |
HirDef::AssociatedConst(..) |
HirDef::PrimTy(_) |
HirDef::GlobalAsm(_) |
HirDef::Err => {
span_bug!(span, "process_def_kind for unexpected item: {:?}", def);
}
}
}

fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
for arg in formals {
self.visit_pat(&arg.pat);
Expand Down Expand Up @@ -1348,29 +1274,17 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
};

let sub_span = self.span.span_for_last_ident(path.span);
let mod_id = match self.lookup_def_id(id) {
Some(def_id) => {
self.process_def_kind(id, path.span, sub_span, def_id);
Some(def_id)
}
None => None,
};

// 'use' always introduces an alias, if there is not an explicit
// one, there is an implicit one.
let sub_span = match self.span.sub_span_after_keyword(use_tree.span,
keywords::As) {
Some(sub_span) => Some(sub_span),
None => sub_span,
};
let alias_span = self.span.sub_span_after_keyword(use_tree.span, keywords::As);
let ref_id = self.lookup_def_id(id);

if !self.span.filter_generated(sub_span, path.span) {
let span =
self.span_from_span(sub_span.expect("No span found for use"));
let span = self.span_from_span(sub_span.expect("No span found for use"));
let alias_span = alias_span.map(|sp| self.span_from_span(sp));
self.dumper.import(&access, Import {
kind: ImportKind::Use,
ref_id: mod_id.map(|id| ::id_from_def_id(id)),
ref_id: ref_id.map(|id| ::id_from_def_id(id)),
span,
alias_span,
name: ident.to_string(),
value: String::new(),
parent,
Expand Down Expand Up @@ -1407,6 +1321,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
kind: ImportKind::GlobUse,
ref_id: None,
span,
alias_span: None,
name: "*".to_owned(),
value: names.join(", "),
parent,
Expand Down Expand Up @@ -1500,6 +1415,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
kind: ImportKind::ExternCrate,
ref_id: None,
span,
alias_span: None,
name: item.ident.to_string(),
value: String::new(),
parent,
Expand Down