@@ -729,6 +729,7 @@ impl NodeInterner {
729729 crate_id : unresolved_trait. crate_id ,
730730 location : Location :: new ( unresolved_trait. trait_def . span , unresolved_trait. file_id ) ,
731731 generics,
732+ visibility : ItemVisibility :: Private ,
732733 self_type_typevar : TypeVariable :: unbound ( self . next_type_variable_id ( ) , Kind :: Normal ) ,
733734 methods : Vec :: new ( ) ,
734735 method_ids : unresolved_trait. method_ids . clone ( ) ,
@@ -2268,31 +2269,26 @@ impl Methods {
22682269 }
22692270
22702271 /// Iterate through each method, starting with the direct methods
2271- pub fn iter ( & self ) -> impl Iterator < Item = ( FuncId , & Option < Type > ) > + ' _ {
2272- let trait_impl_methods = self . trait_impl_methods . iter ( ) . map ( |m| ( m. method , & m. typ ) ) ;
2273- let direct = self . direct . iter ( ) . copied ( ) . map ( |func_id| {
2274- let typ: & Option < Type > = & None ;
2275- ( func_id, typ)
2276- } ) ;
2272+ pub fn iter ( & self ) -> impl Iterator < Item = ( FuncId , Option < & Type > , Option < TraitId > ) > {
2273+ let trait_impl_methods =
2274+ self . trait_impl_methods . iter ( ) . map ( |m| ( m. method , m. typ . as_ref ( ) , Some ( m. trait_id ) ) ) ;
2275+ let direct = self . direct . iter ( ) . copied ( ) . map ( |func_id| ( func_id, None , None ) ) ;
22772276 direct. chain ( trait_impl_methods)
22782277 }
22792278
2280- /// Select the 1 matching method with an object type matching `typ`
2281- pub fn find_matching_method (
2282- & self ,
2283- typ : & Type ,
2279+ pub fn find_matching_methods < ' a > (
2280+ & ' a self ,
2281+ typ : & ' a Type ,
22842282 has_self_param : bool ,
2285- interner : & NodeInterner ,
2286- ) -> Option < FuncId > {
2287- // When adding methods we always check they do not overlap, so there should be
2288- // at most 1 matching method in this list.
2289- for ( method, method_type) in self . iter ( ) {
2283+ interner : & ' a NodeInterner ,
2284+ ) -> impl Iterator < Item = ( FuncId , Option < TraitId > ) > + ' a {
2285+ self . iter ( ) . filter_map ( move |( method, method_type, trait_id) | {
22902286 if Self :: method_matches ( typ, has_self_param, method, method_type, interner) {
2291- return Some ( method) ;
2287+ Some ( ( method, trait_id) )
2288+ } else {
2289+ None
22922290 }
2293- }
2294-
2295- None
2291+ } )
22962292 }
22972293
22982294 pub fn find_direct_method (
@@ -2302,7 +2298,7 @@ impl Methods {
23022298 interner : & NodeInterner ,
23032299 ) -> Option < FuncId > {
23042300 for method in & self . direct {
2305- if Self :: method_matches ( typ, has_self_param, * method, & None , interner) {
2301+ if Self :: method_matches ( typ, has_self_param, * method, None , interner) {
23062302 return Some ( * method) ;
23072303 }
23082304 }
@@ -2320,7 +2316,7 @@ impl Methods {
23202316
23212317 for trait_impl_method in & self . trait_impl_methods {
23222318 let method = trait_impl_method. method ;
2323- let method_type = & trait_impl_method. typ ;
2319+ let method_type = trait_impl_method. typ . as_ref ( ) ;
23242320 let trait_id = trait_impl_method. trait_id ;
23252321
23262322 if Self :: method_matches ( typ, has_self_param, method, method_type, interner) {
@@ -2335,7 +2331,7 @@ impl Methods {
23352331 typ : & Type ,
23362332 has_self_param : bool ,
23372333 method : FuncId ,
2338- method_type : & Option < Type > ,
2334+ method_type : Option < & Type > ,
23392335 interner : & NodeInterner ,
23402336 ) -> bool {
23412337 match interner. function_meta ( & method) . typ . instantiate ( interner) . 0 {
0 commit comments