@@ -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.
310298pub 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.
0 commit comments