Skip to content

Commit 7074380

Browse files
committed
---
yaml --- r: 63193 b: refs/heads/snap-stage3 c: 6bdd4c8 h: refs/heads/master i: 63191: 02e04f3 v: v3
1 parent 78b48e1 commit 7074380

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: febba9f41803e5a782c912131a9e26193ef0ced8
4+
refs/heads/snap-stage3: 6bdd4c854575a6f92501f060e67c60bebea14e03
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/resolve.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,6 @@ pub enum DuplicateCheckingMode {
294294
OverwriteDuplicates
295295
}
296296

297-
// Returns the namespace associated with the given duplicate checking mode,
298-
// or fails for OverwriteDuplicates. This is used for error messages.
299-
pub fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode)
300-
-> Namespace {
301-
match mode {
302-
ForbidDuplicateModules | ForbidDuplicateTypes |
303-
ForbidDuplicateTypesAndValues => TypeNS,
304-
ForbidDuplicateValues => ValueNS,
305-
OverwriteDuplicates => fail!("OverwriteDuplicates has no namespace")
306-
}
307-
}
308-
309297
/// One local scope.
310298
pub struct Rib {
311299
bindings: @mut HashMap<ident,def_like>,
@@ -1007,37 +995,43 @@ impl Resolver {
1007995
// nothing.
1008996

1009997
let mut is_duplicate = false;
1010-
match duplicate_checking_mode {
998+
let ns = match duplicate_checking_mode {
1011999
ForbidDuplicateModules => {
1012-
is_duplicate =
1013-
child.get_module_if_available().is_some();
1000+
is_duplicate = child.get_module_if_available().is_some();
1001+
Some(TypeNS)
10141002
}
10151003
ForbidDuplicateTypes => {
10161004
match child.def_for_namespace(TypeNS) {
10171005
Some(def_mod(_)) | None => {}
10181006
Some(_) => is_duplicate = true
10191007
}
1008+
Some(TypeNS)
10201009
}
10211010
ForbidDuplicateValues => {
10221011
is_duplicate = child.defined_in_namespace(ValueNS);
1012+
Some(ValueNS)
10231013
}
10241014
ForbidDuplicateTypesAndValues => {
1015+
let mut n = None;
10251016
match child.def_for_namespace(TypeNS) {
10261017
Some(def_mod(_)) | None => {}
1027-
Some(_) => is_duplicate = true
1018+
Some(_) => {
1019+
n = Some(TypeNS);
1020+
is_duplicate = true;
1021+
}
10281022
};
10291023
if child.defined_in_namespace(ValueNS) {
10301024
is_duplicate = true;
1025+
n = Some(ValueNS);
10311026
}
1027+
n
10321028
}
1033-
OverwriteDuplicates => {}
1034-
}
1035-
if duplicate_checking_mode != OverwriteDuplicates &&
1036-
is_duplicate {
1029+
OverwriteDuplicates => None
1030+
};
1031+
if is_duplicate {
10371032
// Return an error here by looking up the namespace that
10381033
// had the duplicate.
1039-
let ns = namespace_for_duplicate_checking_mode(
1040-
duplicate_checking_mode);
1034+
let ns = ns.unwrap();
10411035
self.session.span_err(sp,
10421036
fmt!("duplicate definition of %s `%s`",
10431037
namespace_to_str(ns),
@@ -1195,22 +1189,22 @@ impl Resolver {
11951189

11961190
// These items live in both the type and value namespaces.
11971191
item_struct(struct_def, _) => {
1198-
let (name_bindings, new_parent) =
1199-
self.add_child(ident, parent, ForbidDuplicateTypes, sp);
1192+
// Adding to both Type and Value namespaces or just Type?
1193+
let (forbid, ctor_id) = match struct_def.ctor_id {
1194+
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
1195+
None => (ForbidDuplicateTypes, None)
1196+
};
12001197

1201-
name_bindings.define_type(
1202-
privacy, def_ty(local_def(item.id)), sp);
1198+
let (name_bindings, new_parent) = self.add_child(ident, parent, forbid, sp);
12031199

1204-
// If this struct is tuple-like or enum-like, define a name
1205-
// in the value namespace.
1206-
match struct_def.ctor_id {
1207-
None => {}
1208-
Some(ctor_id) => {
1209-
name_bindings.define_value(
1210-
privacy,
1211-
def_struct(local_def(ctor_id)),
1212-
sp);
1213-
}
1200+
// Define a name in the type namespace.
1201+
name_bindings.define_type(privacy, def_ty(local_def(item.id)), sp);
1202+
1203+
// If this is a newtype or unit-like struct, define a name
1204+
// in the value namespace as well
1205+
do ctor_id.while_some |cid| {
1206+
name_bindings.define_value(privacy, def_struct(local_def(cid)), sp);
1207+
None
12141208
}
12151209

12161210
// Record the def ID of this struct.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
static X: int = 0;
12+
struct X; //~ ERROR error: duplicate definition of value `X`
13+
14+
fn main() {}

0 commit comments

Comments
 (0)