Skip to content

Commit 8c1d2ab

Browse files
committed
Local crate half of enum namespacing
1 parent 221fc1e commit 8c1d2ab

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/librustc/middle/resolve.rs

+28
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ enum ModuleKind {
492492
NormalModuleKind,
493493
TraitModuleKind,
494494
ImplModuleKind,
495+
EnumModuleKind,
495496
AnonymousModuleKind,
496497
}
497498

@@ -1282,7 +1283,25 @@ impl<'a> Resolver<'a> {
12821283
name_bindings.define_type
12831284
(DefTy(local_def(item.id), true), sp, is_public);
12841285

1286+
let parent_link = self.get_parent_link(parent.clone(), ident);
1287+
// We want to make sure the module type is EnumModuleKind
1288+
// even if there's already an ImplModuleKind module defined,
1289+
// since that's how we prevent duplicate enum definitions
1290+
name_bindings.set_module_kind(parent_link,
1291+
Some(local_def(item.id)),
1292+
EnumModuleKind,
1293+
false,
1294+
is_public,
1295+
sp);
1296+
12851297
for variant in (*enum_definition).variants.iter() {
1298+
self.build_reduced_graph_for_variant(
1299+
&**variant,
1300+
local_def(item.id),
1301+
ModuleReducedGraphParent(name_bindings.get_module()),
1302+
is_public);
1303+
1304+
// Temporary staging hack
12861305
self.build_reduced_graph_for_variant(
12871306
&**variant,
12881307
local_def(item.id),
@@ -1347,6 +1366,12 @@ impl<'a> Resolver<'a> {
13471366
ImplModuleKind => {
13481367
ModuleReducedGraphParent(child.get_module())
13491368
}
1369+
Some(ref child) if child.get_module_if_available()
1370+
.is_some() &&
1371+
child.get_module().kind.get() ==
1372+
EnumModuleKind => {
1373+
ModuleReducedGraphParent(child.get_module())
1374+
}
13501375
// Create the module
13511376
_ => {
13521377
let name_bindings =
@@ -3400,6 +3425,7 @@ impl<'a> Resolver<'a> {
34003425
}
34013426
TraitModuleKind |
34023427
ImplModuleKind |
3428+
EnumModuleKind |
34033429
AnonymousModuleKind => {
34043430
search_module = parent_module_node.upgrade().unwrap();
34053431
}
@@ -3497,6 +3523,7 @@ impl<'a> Resolver<'a> {
34973523
NormalModuleKind => return Some(new_module),
34983524
TraitModuleKind |
34993525
ImplModuleKind |
3526+
EnumModuleKind |
35003527
AnonymousModuleKind => module_ = new_module,
35013528
}
35023529
}
@@ -3512,6 +3539,7 @@ impl<'a> Resolver<'a> {
35123539
NormalModuleKind => return module_,
35133540
TraitModuleKind |
35143541
ImplModuleKind |
3542+
EnumModuleKind |
35153543
AnonymousModuleKind => {
35163544
match self.get_nearest_normal_module_parent(module_.clone()) {
35173545
None => module_,

src/test/compile-fail/enum-and-module-in-same-scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod Foo {
1313
}
1414

1515
enum Foo { //~ ERROR duplicate definition of type or module `Foo`
16-
X
16+
X //~ ERROR duplicate definition of value `X`
1717
}
1818

1919
fn main() {}

0 commit comments

Comments
 (0)