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

Fix translation of external spans #42507

Merged
merged 1 commit into from
Jun 9, 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: 8 additions & 4 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub trait CrateStore {

// item info
fn visibility(&self, def: DefId) -> ty::Visibility;
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>>;
fn visible_parent_map<'a>(&'a self, sess: &Session) -> ::std::cell::Ref<'a, DefIdMap<DefId>>;
fn item_generics_cloned(&self, def: DefId) -> ty::Generics;

// trait info
Expand Down Expand Up @@ -285,7 +285,7 @@ pub trait CrateStore {
fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash;
fn def_path_table(&self, cnum: CrateNum) -> Rc<DefPathTable>;
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
fn item_children(&self, did: DefId) -> Vec<def::Export>;
fn item_children(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;

// misc. metadata
Expand Down Expand Up @@ -347,7 +347,9 @@ impl CrateStore for DummyCrateStore {
{ bug!("crate_data_as_rc_any") }
// item info
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
fn visible_parent_map<'a>(&'a self, session: &Session)
-> ::std::cell::Ref<'a, DefIdMap<DefId>>
{
bug!("visible_parent_map")
}
fn item_generics_cloned(&self, def: DefId) -> ty::Generics
Expand Down Expand Up @@ -421,7 +423,9 @@ impl CrateStore for DummyCrateStore {
bug!("def_path_table")
}
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children") }
fn item_children(&self, did: DefId, sess: &Session) -> Vec<def::Export> {
bug!("item_children")
}
fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }

// misc. metadata
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn try_push_visible_item_path<T>(self, buffer: &mut T, external_def_id: DefId) -> bool
where T: ItemPathBuffer
{
let visible_parent_map = self.sess.cstore.visible_parent_map();
let visible_parent_map = self.sess.cstore.visible_parent_map(self.sess);

let (mut cur_def, mut cur_path) = (external_def_id, Vec::<ast::Name>::new());
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ provide! { <'tcx> tcx, def_id, cdata
variances_of => { Rc::new(cdata.get_item_variances(def_id.index)) }
associated_item_def_ids => {
let mut result = vec![];
cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id()));
cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id()), tcx.sess);
Rc::new(result)
}
associated_item => { cdata.get_associated_item(def_id.index) }
Expand Down Expand Up @@ -348,12 +348,12 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(def.krate).get_struct_field_names(def.index)
}

fn item_children(&self, def_id: DefId) -> Vec<def::Export>
fn item_children(&self, def_id: DefId, sess: &Session) -> Vec<def::Export>
{
self.dep_graph.read(DepNode::MetaData(def_id));
let mut result = vec![];
self.get_crate_data(def_id.krate)
.each_child_of_item(def_id.index, |child| result.push(child));
.each_child_of_item(def_id.index, |child| result.push(child), sess);
result
}

Expand Down Expand Up @@ -456,7 +456,7 @@ impl CrateStore for cstore::CStore {
/// Returns a map from a sufficiently visible external item (i.e. an external item that is
/// visible from at least one local module) to a sufficiently visible parent (considering
/// modules that re-export the external item to be parents).
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
fn visible_parent_map<'a>(&'a self, sess: &Session) -> ::std::cell::Ref<'a, DefIdMap<DefId>> {
{
let visible_parent_map = self.visible_parent_map.borrow();
if !visible_parent_map.is_empty() {
Expand Down Expand Up @@ -506,7 +506,7 @@ impl CrateStore for cstore::CStore {
index: CRATE_DEF_INDEX
});
while let Some(def) = bfs_queue.pop_front() {
for child in self.item_children(def) {
for child in self.item_children(def, sess) {
add_child(bfs_queue, child, def);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl<'a, 'tcx> CrateMetadata {
}

/// Iterates over each child of the given item.
pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F)
pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Session)
where F: FnMut(def::Export)
{
if let Some(ref proc_macros) = self.proc_macros {
Expand All @@ -676,19 +676,19 @@ impl<'a, 'tcx> CrateMetadata {
// Find the item.
let item = match self.maybe_entry(id) {
None => return,
Some(item) => item.decode(self),
Some(item) => item.decode((self, sess)),
};

// Iterate over all children.
let macros_only = self.dep_kind.get().macros_only();
for child_index in item.children.decode(self) {
for child_index in item.children.decode((self, sess)) {
if macros_only {
continue
}

// Get the item.
if let Some(child) = self.maybe_entry(child_index) {
let child = child.decode(self);
let child = child.decode((self, sess));
match child.kind {
EntryKind::MacroDef(..) => {}
_ if macros_only => continue,
Expand All @@ -699,12 +699,12 @@ impl<'a, 'tcx> CrateMetadata {
match child.kind {
// FIXME(eddyb) Don't encode these in children.
EntryKind::ForeignMod => {
for child_index in child.children.decode(self) {
for child_index in child.children.decode((self, sess)) {
if let Some(def) = self.get_def(child_index) {
callback(def::Export {
def: def,
ident: Ident::with_empty_ctxt(self.item_name(child_index)),
span: self.entry(child_index).span.decode(self),
span: self.entry(child_index).span.decode((self, sess)),
});
}
}
Expand All @@ -717,7 +717,7 @@ impl<'a, 'tcx> CrateMetadata {
}

let def_key = self.def_key(child_index);
let span = child.span.decode(self);
let span = child.span.decode((self, sess));
if let (Some(def), Some(name)) =
(self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) {
let ident = Ident::with_empty_ctxt(name);
Expand Down Expand Up @@ -746,7 +746,7 @@ impl<'a, 'tcx> CrateMetadata {
}

if let EntryKind::Mod(data) = item.kind {
for exp in data.decode(self).reexports.decode(self) {
for exp in data.decode((self, sess)).reexports.decode((self, sess)) {
match exp.def {
Def::Macro(..) => {}
_ if macros_only => continue,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<'a> Resolver<'a> {
span);
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));

for child in self.session.cstore.item_children(def_id) {
for child in self.session.cstore.item_children(def_id, self.session) {
let ns = if let Def::AssociatedTy(..) = child.def { TypeNS } else { ValueNS };
self.define(module, child.ident, ns,
(child.def, ty::Visibility::Public, DUMMY_SP, expansion));
Expand Down Expand Up @@ -564,7 +564,7 @@ impl<'a> Resolver<'a> {
/// is built, building it if it is not.
pub fn populate_module_if_necessary(&mut self, module: Module<'a>) {
if module.populated.get() { return }
for child in self.session.cstore.item_children(module.def_id().unwrap()) {
for child in self.session.cstore.item_children(module.def_id().unwrap(), self.session) {
self.build_reduced_graph_for_external_crate_def(module, child);
}
module.populated.set(true)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ pub fn all_traits<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> AllTraits<'a>
if !external_mods.insert(def_id) {
return;
}
for child in tcx.sess.cstore.item_children(def_id) {
for child in tcx.sess.cstore.item_children(def_id, tcx.sess) {
handle_external_def(tcx, traits, external_mods, child.def)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ fn build_module(cx: &DocContext, did: DefId) -> clean::Module {
// two namespaces, so the target may be listed twice. Make sure we only
// visit each node at most once.
let mut visited = FxHashSet();
for item in cx.tcx.sess.cstore.item_children(did) {
for item in cx.tcx.sess.cstore.item_children(did, cx.tcx.sess) {
let def_id = item.def.def_id();
if cx.tcx.sess.cstore.visibility(def_id) == ty::Visibility::Public {
if !visited.insert(def_id) { continue }
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Clean<ExternalCrate> for CrateNum {
}
}).collect()
} else {
cx.tcx.sess.cstore.item_children(root).iter().map(|item| item.def)
cx.tcx.sess.cstore.item_children(root, cx.tcx.sess).iter().map(|item| item.def)
.filter_map(as_primitive).collect()
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> {
return;
}

for item in self.cstore.item_children(def_id) {
for item in self.cstore.item_children(def_id, self.cx.tcx.sess) {
self.visit_item(item.def);
}
}
Expand Down