Skip to content

Commit

Permalink
Do not allow a module and tuple struct of the same name to coexist.
Browse files Browse the repository at this point in the history
Fixes #21546.
  • Loading branch information
Nick Hamann committed Jun 19, 2015
1 parent ff8fee1 commit d6c0753
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum DuplicateCheckingMode {
ForbidDuplicateTypesAndModules,
ForbidDuplicateValues,
ForbidDuplicateTypesAndValues,
ForbidDuplicateTypesModulesValues,
OverwriteDuplicates
}

Expand Down Expand Up @@ -202,6 +203,18 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
}
n
}
ForbidDuplicateTypesModulesValues => {
let mut n = None;
if child.defined_in_namespace(TypeNS) {
duplicate_type = TypeError;
n = Some(TypeNS);
}
if child.defined_in_namespace(ValueNS) {
duplicate_type = ValueError;
n = Some(ValueNS);
}
n
}
OverwriteDuplicates => None
};
if duplicate_type != NoError {
Expand Down Expand Up @@ -480,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
ItemStruct(ref struct_def, _) => {
// Adding to both Type and Value namespaces or just Type?
let (forbid, ctor_id) = match struct_def.ctor_id {
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
Some(ctor_id) => (ForbidDuplicateTypesModulesValues, Some(ctor_id)),
None => (ForbidDuplicateTypesAndModules, None)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Also works as a test for #14564

mod Foo { }
//~^ NOTE first definition of type or module

struct Foo;
//~^ ERROR duplicate definition of type or module `Foo`

impl Foo { }

fn main() { }

0 comments on commit d6c0753

Please sign in to comment.