Skip to content
Closed
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
5 changes: 2 additions & 3 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use middle::subst::ParamSpace;
use util::nodemap::NodeMap;
use syntax::ast;
use rustc_front::hir;
use std::collections::HashSet;

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Def {
Expand Down Expand Up @@ -100,9 +99,9 @@ impl PathResolution {
pub type DefMap = NodeMap<PathResolution>;
// This is the replacement export map. It maps a module to all of the exports
// within.
pub type ExportMap = NodeMap<HashSet<Export>>;
pub type ExportMap = NodeMap<Vec<Export>>;

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone)]
pub struct Export {
pub name: ast::Name, // The name of the target.
pub def_id: DefId, // The definition of the target.
Expand Down
16 changes: 11 additions & 5 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
import_resolution.id = directive.id;
import_resolution.is_public = directive.is_public;

self.add_export(module_, target, &import_resolution);
self.add_export(module_, target, namespace, &import_resolution);
*used_public = name_binding.is_public();
}
Failed(_) => {
Expand Down Expand Up @@ -716,7 +716,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
dest_import_resolution.id = id;
dest_import_resolution.is_public = is_public;
dest_import_resolution.target = Some(target.clone());
self.add_export(module_, name, &dest_import_resolution);
self.add_export(module_, name, ns, &dest_import_resolution);
}
_ => {}
}
Expand Down Expand Up @@ -796,7 +796,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
dest_import_resolution.target = Some(target);
dest_import_resolution.id = id;
dest_import_resolution.is_public = is_public;
self.add_export(module_, name, &dest_import_resolution);
self.add_export(module_, name, ns, &dest_import_resolution);
}
} else {
// FIXME #30159: This is required for backwards compatability.
Expand All @@ -809,17 +809,23 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
(name, ns));
}

fn add_export(&mut self, module: Module<'b>, name: Name, resolution: &ImportResolution<'b>) {
fn add_export(&mut self,
module: Module<'b>,
name: Name,
ns: Namespace,
resolution: &ImportResolution<'b>) {
if !resolution.is_public { return }
let node_id = match module.def_id() {
Some(def_id) => self.resolver.ast_map.as_local_node_id(def_id).unwrap(),
None => return,
};
let export = match resolution.target.as_ref().unwrap().binding.def() {
// A Def::Variant defines both namespaces, so only export it once per name.
Some(Def::Variant(..)) if ns != TypeNS => return,
Some(def) => Export { name: name, def_id: def.def_id() },
None => return,
};
self.resolver.export_map.entry(node_id).or_insert(Default::default()).insert(export);
self.resolver.export_map.entry(node_id).or_insert(Vec::new()).push(export);
}

/// Checks that imported names and items don't have the same name.
Expand Down