Skip to content

Commit 432b7d1

Browse files
committed
Instead of using a hash set to prevent duplicates, explicitly avoid reexporting variants twice
1 parent 638bd4e commit 432b7d1

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/librustc/middle/def.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::subst::ParamSpace;
1414
use util::nodemap::NodeMap;
1515
use syntax::ast;
1616
use rustc_front::hir;
17-
use std::collections::HashSet;
1817

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

105-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
104+
#[derive(Copy, Clone)]
106105
pub struct Export {
107106
pub name: ast::Name, // The name of the target.
108107
pub def_id: DefId, // The definition of the target.

src/librustc_resolve/resolve_imports.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
574574
import_resolution.id = directive.id;
575575
import_resolution.is_public = directive.is_public;
576576

577-
self.add_export(module_, target, &import_resolution);
577+
self.add_export(module_, target, namespace, &import_resolution);
578578
*used_public = name_binding.is_public();
579579
}
580580
Failed(_) => {
@@ -716,7 +716,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
716716
dest_import_resolution.id = id;
717717
dest_import_resolution.is_public = is_public;
718718
dest_import_resolution.target = Some(target.clone());
719-
self.add_export(module_, name, &dest_import_resolution);
719+
self.add_export(module_, name, ns, &dest_import_resolution);
720720
}
721721
_ => {}
722722
}
@@ -796,7 +796,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
796796
dest_import_resolution.target = Some(target);
797797
dest_import_resolution.id = id;
798798
dest_import_resolution.is_public = is_public;
799-
self.add_export(module_, name, &dest_import_resolution);
799+
self.add_export(module_, name, ns, &dest_import_resolution);
800800
}
801801
} else {
802802
// FIXME #30159: This is required for backwards compatability.
@@ -809,17 +809,23 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
809809
(name, ns));
810810
}
811811

812-
fn add_export(&mut self, module: Module<'b>, name: Name, resolution: &ImportResolution<'b>) {
812+
fn add_export(&mut self,
813+
module: Module<'b>,
814+
name: Name,
815+
ns: Namespace,
816+
resolution: &ImportResolution<'b>) {
813817
if !resolution.is_public { return }
814818
let node_id = match module.def_id() {
815819
Some(def_id) => self.resolver.ast_map.as_local_node_id(def_id).unwrap(),
816820
None => return,
817821
};
818822
let export = match resolution.target.as_ref().unwrap().binding.def() {
823+
// A Def::Variant defines both namespaces, so only export it once per name.
824+
Some(Def::Variant(..)) if ns != TypeNS => return,
819825
Some(def) => Export { name: name, def_id: def.def_id() },
820826
None => return,
821827
};
822-
self.resolver.export_map.entry(node_id).or_insert(Default::default()).insert(export);
828+
self.resolver.export_map.entry(node_id).or_insert(Vec::new()).push(export);
823829
}
824830

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

0 commit comments

Comments
 (0)