Skip to content

save-analysis: add parents to imports #46540

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 3 commits into from
Dec 16, 2017
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
12 changes: 11 additions & 1 deletion 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 @@ -15,7 +15,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_typeck = { path = "../librustc_typeck" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rls-data = "0.13"
rls-data = "0.14"
rls-span = "0.4"
# FIXME(#40527) should move rustc serialize out of tree
rustc-serialize = "0.3"
25 changes: 22 additions & 3 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,13 +1231,26 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
}
}

/// Dumps imports in a use tree recursively.
///
/// A use tree is an import that may contain nested braces (RFC 2128). The `use_tree` parameter
/// is the current use tree under scrutiny, while `id` and `prefix` are its corresponding node
/// id and path. `root_item` is the topmost use tree in the hierarchy.
///
/// If `use_tree` is a simple or glob import, it is dumped into the analysis data. Otherwise,
/// each child use tree is dumped recursively.
fn process_use_tree(&mut self,
use_tree: &'l ast::UseTree,
id: NodeId,
parent_item: &'l ast::Item,
root_item: &'l ast::Item,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to the function here explaining what the root_item is please? Also perhaps what a use_tree is.

prefix: &ast::Path) {
let path = &use_tree.prefix;
let access = access_from!(self.save_ctxt, parent_item);
let access = access_from!(self.save_ctxt, root_item);

// The parent def id of a given use tree is always the enclosing item.
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(id)
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
.map(::id_from_def_id);

match use_tree.kind {
ast::UseTreeKind::Simple(ident) => {
Expand Down Expand Up @@ -1276,6 +1289,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
span,
name: ident.to_string(),
value: String::new(),
parent,
});
}
self.write_sub_paths_truncated(&path);
Expand Down Expand Up @@ -1311,6 +1325,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
span,
name: "*".to_owned(),
value: names.join(", "),
parent,
});
}
self.write_sub_paths(&path);
Expand All @@ -1325,7 +1340,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
span: path.span,
};
for &(ref tree, id) in nested_items {
self.process_use_tree(tree, id, parent_item, &prefix);
self.process_use_tree(tree, id, root_item, &prefix);
}
}
}
Expand Down Expand Up @@ -1389,6 +1404,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
if !self.span.filter_generated(alias_span, item.span) {
let span =
self.span_from_span(alias_span.expect("No span found for extern crate"));
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(item.id)
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
.map(::id_from_def_id);
self.dumper.import(
&Access {
public: false,
Expand All @@ -1400,6 +1418,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
span,
name: item.ident.to_string(),
value: String::new(),
parent,
},
);
}
Expand Down