Skip to content

Commit d6c0753

Browse files
author
Nick Hamann
committed
Do not allow a module and tuple struct of the same name to coexist.
Fixes rust-lang#21546.
1 parent ff8fee1 commit d6c0753

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/librustc_resolve/build_reduced_graph.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum DuplicateCheckingMode {
6767
ForbidDuplicateTypesAndModules,
6868
ForbidDuplicateValues,
6969
ForbidDuplicateTypesAndValues,
70+
ForbidDuplicateTypesModulesValues,
7071
OverwriteDuplicates
7172
}
7273

@@ -202,6 +203,18 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
202203
}
203204
n
204205
}
206+
ForbidDuplicateTypesModulesValues => {
207+
let mut n = None;
208+
if child.defined_in_namespace(TypeNS) {
209+
duplicate_type = TypeError;
210+
n = Some(TypeNS);
211+
}
212+
if child.defined_in_namespace(ValueNS) {
213+
duplicate_type = ValueError;
214+
n = Some(ValueNS);
215+
}
216+
n
217+
}
205218
OverwriteDuplicates => None
206219
};
207220
if duplicate_type != NoError {
@@ -480,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
480493
ItemStruct(ref struct_def, _) => {
481494
// Adding to both Type and Value namespaces or just Type?
482495
let (forbid, ctor_id) = match struct_def.ctor_id {
483-
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
496+
Some(ctor_id) => (ForbidDuplicateTypesModulesValues, Some(ctor_id)),
484497
None => (ForbidDuplicateTypesAndModules, None)
485498
};
486499

src/test/run-pass/issue-14564.rs src/test/compile-fail/issue-21546.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Also works as a test for #14564
12+
1113
mod Foo { }
14+
//~^ NOTE first definition of type or module
15+
1216
struct Foo;
17+
//~^ ERROR duplicate definition of type or module `Foo`
18+
1319
impl Foo { }
1420

1521
fn main() { }

0 commit comments

Comments
 (0)