@@ -101,6 +101,14 @@ pub enum Namespace {
101
101
ValueNS
102
102
}
103
103
104
+ #[ deriving( Eq ) ]
105
+ pub enum NamespaceError {
106
+ NoError ,
107
+ ModuleError ,
108
+ TypeError ,
109
+ ValueError
110
+ }
111
+
104
112
/// A NamespaceResult represents the result of resolving an import in
105
113
/// a particular namespace. The result is either definitely-resolved,
106
114
/// definitely- unresolved, or unknown.
@@ -759,10 +767,12 @@ pub fn PrimitiveTypeTable() -> PrimitiveTypeTable {
759
767
}
760
768
761
769
762
- pub fn namespace_to_str ( ns : Namespace ) -> ~ str {
770
+ pub fn namespace_error_to_str ( ns : NamespaceError ) -> & ' static str {
763
771
match ns {
764
- TypeNS => ~"type ",
765
- ValueNS => ~"value",
772
+ NoError => "" ,
773
+ ModuleError => "module" ,
774
+ TypeError => "type" ,
775
+ ValueError => "value" ,
766
776
}
767
777
}
768
778
@@ -993,21 +1003,25 @@ impl Resolver {
993
1003
// * If no duplicate checking was requested at all, do
994
1004
// nothing.
995
1005
996
- let mut is_duplicate = false ;
1006
+ let mut duplicate_type = NoError ;
997
1007
let ns = match duplicate_checking_mode {
998
1008
ForbidDuplicateModules => {
999
- is_duplicate = child. get_module_if_available ( ) . is_some ( ) ;
1009
+ if ( child. get_module_if_available ( ) . is_some ( ) ) {
1010
+ duplicate_type = ModuleError ;
1011
+ }
1000
1012
Some ( TypeNS )
1001
1013
}
1002
1014
ForbidDuplicateTypes => {
1003
1015
match child. def_for_namespace ( TypeNS ) {
1004
1016
Some ( def_mod( _) ) | None => { }
1005
- Some ( _) => is_duplicate = true
1017
+ Some ( _) => duplicate_type = TypeError
1006
1018
}
1007
1019
Some ( TypeNS )
1008
1020
}
1009
1021
ForbidDuplicateValues => {
1010
- is_duplicate = child. defined_in_namespace ( ValueNS ) ;
1022
+ if child. defined_in_namespace ( ValueNS ) {
1023
+ duplicate_type = ValueError ;
1024
+ }
1011
1025
Some ( ValueNS )
1012
1026
}
1013
1027
ForbidDuplicateTypesAndValues => {
@@ -1016,31 +1030,31 @@ impl Resolver {
1016
1030
Some ( def_mod( _) ) | None => { }
1017
1031
Some ( _) => {
1018
1032
n = Some ( TypeNS ) ;
1019
- is_duplicate = true ;
1033
+ duplicate_type = TypeError ;
1020
1034
}
1021
1035
} ;
1022
1036
if child. defined_in_namespace ( ValueNS ) {
1023
- is_duplicate = true ;
1037
+ duplicate_type = ValueError ;
1024
1038
n = Some ( ValueNS ) ;
1025
1039
}
1026
1040
n
1027
1041
}
1028
1042
OverwriteDuplicates => None
1029
1043
} ;
1030
- if is_duplicate {
1044
+ if ( duplicate_type != NoError ) {
1031
1045
// Return an error here by looking up the namespace that
1032
1046
// had the duplicate.
1033
1047
let ns = ns. unwrap ( ) ;
1034
1048
self . session . span_err ( sp,
1035
1049
fmt ! ( "duplicate definition of %s `%s`" ,
1036
- namespace_to_str ( ns ) ,
1050
+ namespace_error_to_str ( duplicate_type ) ,
1037
1051
self . session. str_of( name) ) ) ;
1038
1052
{
1039
1053
let r = child. span_for_namespace ( ns) ;
1040
1054
for r. iter( ) . advance |sp| {
1041
1055
self . session. span_note( * sp,
1042
- fmt ! ( "first definition of %s %s here: " ,
1043
- namespace_to_str ( ns ) ,
1056
+ fmt ! ( "first definition of %s `%s` here" ,
1057
+ namespace_error_to_str ( duplicate_type ) ,
1044
1058
self . session. str_of( name) ) ) ;
1045
1059
}
1046
1060
}
0 commit comments