@@ -734,7 +734,7 @@ pub fn Resolver(session: Session,
734
734
735
735
graph_root : graph_root,
736
736
737
- trait_info : HashMap :: new ( ) ,
737
+ method_map : @ mut HashMap :: new ( ) ,
738
738
structs : HashSet :: new ( ) ,
739
739
740
740
unresolved_imports : 0 ,
@@ -776,7 +776,7 @@ pub struct Resolver {
776
776
777
777
graph_root : @mut NameBindings ,
778
778
779
- trait_info : HashMap < def_id , HashSet < ident > > ,
779
+ method_map : @ mut HashMap < ident , HashSet < def_id > > ,
780
780
structs : HashSet < def_id > ,
781
781
782
782
// The number of imports that are currently unresolved.
@@ -1292,7 +1292,15 @@ pub impl Resolver {
1292
1292
}
1293
1293
1294
1294
let def_id = local_def ( item. id ) ;
1295
- self . trait_info . insert ( def_id, method_names) ;
1295
+ for method_names. each |name| {
1296
+ if !self . method_map . contains_key ( name) {
1297
+ self . method_map . insert ( * name, HashSet :: new ( ) ) ;
1298
+ }
1299
+ match self . method_map . find_mut ( name) {
1300
+ Some ( s) => { s. insert ( def_id) ; } ,
1301
+ _ => fail ! ( "Can't happen" ) ,
1302
+ }
1303
+ }
1296
1304
1297
1305
name_bindings. define_type ( privacy, def_trait ( def_id) , sp) ;
1298
1306
visit_item ( item, new_parent, visitor) ;
@@ -1589,7 +1597,15 @@ pub impl Resolver {
1589
1597
interned_method_names. insert ( method_name) ;
1590
1598
}
1591
1599
}
1592
- self . trait_info . insert ( def_id, interned_method_names) ;
1600
+ for interned_method_names. each |name| {
1601
+ if !self . method_map . contains_key ( name) {
1602
+ self . method_map . insert ( * name, HashSet :: new ( ) ) ;
1603
+ }
1604
+ match self . method_map . find_mut ( name) {
1605
+ Some ( s) => { s. insert ( def_id) ; } ,
1606
+ _ => fail ! ( "Can't happen" ) ,
1607
+ }
1608
+ }
1593
1609
1594
1610
child_name_bindings. define_type ( Public , def, dummy_sp ( ) ) ;
1595
1611
}
@@ -4935,118 +4951,111 @@ pub impl Resolver {
4935
4951
debug ! ( "(searching for traits containing method) looking for '%s'" ,
4936
4952
* self . session. str_of( name) ) ;
4937
4953
4954
+
4938
4955
let mut found_traits = ~[ ] ;
4939
4956
let mut search_module = self . current_module;
4940
- loop {
4941
- // Look for the current trait.
4942
- match /*bad*/ copy self. current_trait_refs {
4943
- Some ( trait_def_ids) => {
4944
- for trait_def_ids. each |trait_def_id| {
4945
- self . add_trait_info_if_containing_method(
4946
- & mut found_traits, * trait_def_id, name) ;
4947
- }
4948
- }
4949
- None => {
4950
- // Nothing to do.
4951
- }
4952
- }
4953
-
4954
- // Look for trait children.
4955
- for search_module. children. each_value |& child_name_bindings| {
4956
- match child_name_bindings. def_for_namespace( TypeNS ) {
4957
- Some ( def) => {
4958
- match def {
4959
- def_trait( trait_def_id) => {
4960
- self . add_trait_info_if_containing_method(
4961
- & mut found_traits, trait_def_id, name) ;
4962
- }
4963
- _ => {
4964
- // Continue.
4957
+ match self . method_map. find( & name) {
4958
+ Some ( candidate_traits) => loop {
4959
+ // Look for the current trait.
4960
+ match /*bad*/ copy self. current_trait_refs {
4961
+ Some ( trait_def_ids) => {
4962
+ for trait_def_ids. each |trait_def_id| {
4963
+ if candidate_traits. contains( trait_def_id) {
4964
+ self . add_trait_info(
4965
+ & mut found_traits,
4966
+ * trait_def_id, name) ;
4965
4967
}
4966
4968
}
4967
4969
}
4968
4970
None => {
4969
- // Continue .
4971
+ // Nothing to do .
4970
4972
}
4971
4973
}
4972
- }
4973
4974
4974
- // Look for imports.
4975
- for search_module. import_resolutions. each_value
4976
- |& import_resolution| {
4977
-
4978
- match import_resolution. target_for_namespace( TypeNS ) {
4979
- None => {
4980
- // Continue.
4981
- }
4982
- Some ( target) => {
4983
- match target. bindings. def_for_namespace( TypeNS ) {
4984
- Some ( def) => {
4985
- match def {
4986
- def_trait( trait_def_id) => {
4987
- let added = self .
4988
- add_trait_info_if_containing_method(
4975
+ // Look for trait children.
4976
+ for search_module. children. each_value |& child_name_bindings| {
4977
+ match child_name_bindings. def_for_namespace( TypeNS ) {
4978
+ Some ( def) => {
4979
+ match def {
4980
+ def_trait( trait_def_id) => {
4981
+ if candidate_traits. contains( & trait_def_id) {
4982
+ self . add_trait_info(
4989
4983
& mut found_traits,
4990
4984
trait_def_id, name) ;
4991
- if added {
4992
- self. used_imports. insert(
4993
- import_resolution. id) ;
4994
- }
4995
- }
4996
- _ => {
4997
- // Continue.
4998
4985
}
4999
4986
}
5000
- }
5001
- None => {
5002
- // Continue.
4987
+ _ => {
4988
+ // Continue.
4989
+ }
5003
4990
}
5004
4991
}
4992
+ None => {
4993
+ // Continue.
4994
+ }
5005
4995
}
5006
4996
}
5007
- }
5008
4997
5009
- // Move to the next parent.
5010
- match search_module. parent_link {
5011
- NoParentLink => {
5012
- // Done.
5013
- break;
4998
+ // Look for imports.
4999
+ for search_module. import_resolutions. each_value
5000
+ |& import_resolution| {
5001
+
5002
+ match import_resolution. target_for_namespace( TypeNS ) {
5003
+ None => {
5004
+ // Continue.
5005
+ }
5006
+ Some ( target) => {
5007
+ match target. bindings. def_for_namespace( TypeNS ) {
5008
+ Some ( def) => {
5009
+ match def {
5010
+ def_trait( trait_def_id) => {
5011
+ if candidate_traits. contains( & trait_def_id) {
5012
+ self . add_trait_info(
5013
+ & mut found_traits,
5014
+ trait_def_id, name) ;
5015
+ self . used_imports. insert(
5016
+ import_resolution. id) ;
5017
+ }
5018
+ }
5019
+ _ => {
5020
+ // Continue.
5021
+ }
5022
+ }
5023
+ }
5024
+ None => {
5025
+ // Continue.
5026
+ }
5027
+ }
5028
+ }
5029
+ }
5014
5030
}
5015
- ModuleParentLink ( parent_module, _) |
5016
- BlockParentLink ( parent_module, _) => {
5017
- search_module = parent_module;
5031
+
5032
+ // Move to the next parent.
5033
+ match search_module. parent_link {
5034
+ NoParentLink => {
5035
+ // Done.
5036
+ break;
5037
+ }
5038
+ ModuleParentLink ( parent_module, _) |
5039
+ BlockParentLink ( parent_module, _) => {
5040
+ search_module = parent_module;
5041
+ }
5018
5042
}
5019
- }
5043
+ } ,
5044
+ _ => ( )
5020
5045
}
5021
5046
5022
5047
return found_traits;
5023
5048
}
5024
5049
5025
- fn add_trait_info_if_containing_method( & self ,
5026
- found_traits: & mut ~[ def_id] ,
5027
- trait_def_id: def_id,
5028
- name: ident)
5029
- -> bool {
5030
- debug ! ( "(adding trait info if containing method) trying trait %d:%d \
5031
- for method '%s'",
5050
+ fn add_trait_info( & self ,
5051
+ found_traits: & mut ~[ def_id] ,
5052
+ trait_def_id: def_id,
5053
+ name: ident) {
5054
+ debug ! ( "(adding trait info) found trait %d:%d for method '%s'" ,
5032
5055
trait_def_id. crate ,
5033
5056
trait_def_id. node,
5034
5057
* self . session. str_of( name) ) ;
5035
-
5036
- match self . trait_info. find( & trait_def_id) {
5037
- Some ( trait_info) if trait_info. contains( & name) => {
5038
- debug ! ( "(adding trait info if containing method) found trait \
5039
- %d:%d for method '%s'",
5040
- trait_def_id. crate ,
5041
- trait_def_id. node,
5042
- * self . session. str_of( name) ) ;
5043
- found_traits. push( trait_def_id) ;
5044
- true
5045
- }
5046
- Some ( _) | None => {
5047
- false
5048
- }
5049
- }
5058
+ found_traits. push( trait_def_id) ;
5050
5059
}
5051
5060
5052
5061
fn add_fixed_trait_for_expr( @mut self ,
0 commit comments