@@ -294,18 +294,6 @@ pub enum DuplicateCheckingMode {
294
294
OverwriteDuplicates
295
295
}
296
296
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
-
309
297
/// One local scope.
310
298
pub struct Rib {
311
299
bindings : @mut HashMap < ident , def_like > ,
@@ -1007,37 +995,43 @@ impl Resolver {
1007
995
// nothing.
1008
996
1009
997
let mut is_duplicate = false ;
1010
- match duplicate_checking_mode {
998
+ let ns = match duplicate_checking_mode {
1011
999
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 )
1014
1002
}
1015
1003
ForbidDuplicateTypes => {
1016
1004
match child. def_for_namespace ( TypeNS ) {
1017
1005
Some ( def_mod( _) ) | None => { }
1018
1006
Some ( _) => is_duplicate = true
1019
1007
}
1008
+ Some ( TypeNS )
1020
1009
}
1021
1010
ForbidDuplicateValues => {
1022
1011
is_duplicate = child. defined_in_namespace ( ValueNS ) ;
1012
+ Some ( ValueNS )
1023
1013
}
1024
1014
ForbidDuplicateTypesAndValues => {
1015
+ let mut n = None ;
1025
1016
match child. def_for_namespace ( TypeNS ) {
1026
1017
Some ( def_mod( _) ) | None => { }
1027
- Some ( _) => is_duplicate = true
1018
+ Some ( _) => {
1019
+ n = Some ( TypeNS ) ;
1020
+ is_duplicate = true ;
1021
+ }
1028
1022
} ;
1029
1023
if child. defined_in_namespace ( ValueNS ) {
1030
1024
is_duplicate = true ;
1025
+ n = Some ( ValueNS ) ;
1031
1026
}
1027
+ n
1032
1028
}
1033
- OverwriteDuplicates => { }
1034
- }
1035
- if duplicate_checking_mode != OverwriteDuplicates &&
1036
- is_duplicate {
1029
+ OverwriteDuplicates => None
1030
+ } ;
1031
+ if is_duplicate {
1037
1032
// Return an error here by looking up the namespace that
1038
1033
// had the duplicate.
1039
- let ns = namespace_for_duplicate_checking_mode (
1040
- duplicate_checking_mode) ;
1034
+ let ns = ns. unwrap ( ) ;
1041
1035
self . session . span_err ( sp,
1042
1036
fmt ! ( "duplicate definition of %s `%s`" ,
1043
1037
namespace_to_str( ns) ,
@@ -1195,22 +1189,22 @@ impl Resolver {
1195
1189
1196
1190
// These items live in both the type and value namespaces.
1197
1191
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
+ } ;
1200
1197
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) ;
1203
1199
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
1214
1208
}
1215
1209
1216
1210
// Record the def ID of this struct.
0 commit comments