@@ -19,7 +19,7 @@ use hir::def::Def;
19
19
use rustc:: ty:: subst:: { Subst , Substs } ;
20
20
use rustc:: traits;
21
21
use rustc:: ty:: { self , Ty , ToPolyTraitRef , TraitRef , TypeFoldable } ;
22
- use rustc:: infer:: { InferOk , TypeOrigin } ;
22
+ use rustc:: infer:: { self , InferOk , TypeOrigin } ;
23
23
use rustc:: util:: nodemap:: FnvHashSet ;
24
24
use syntax:: ast;
25
25
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -636,35 +636,35 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
636
636
Ok ( ( ) )
637
637
}
638
638
639
+ pub fn matches_return_type ( & self , method : & ty:: ImplOrTraitItem < ' tcx > ,
640
+ expected : ty:: Ty < ' tcx > ) -> bool {
641
+ match * method {
642
+ ty:: ImplOrTraitItem :: MethodTraitItem ( ref x) => {
643
+ self . probe ( |_| {
644
+ let output = self . replace_late_bound_regions_with_fresh_var (
645
+ self . span , infer:: FnCall , & x. fty . sig . output ( ) ) ;
646
+ self . can_sub_types ( output. 0 , expected) . is_ok ( )
647
+ } )
648
+ }
649
+ _ => false ,
650
+ }
651
+ }
652
+
639
653
fn assemble_extension_candidates_for_trait ( & mut self ,
640
654
trait_def_id : DefId )
641
655
-> Result < ( ) , MethodError < ' tcx > > {
642
656
debug ! ( "assemble_extension_candidates_for_trait(trait_def_id={:?})" ,
643
657
trait_def_id) ;
644
658
645
- // Check whether `trait_def_id` defines a method with suitable name:
646
- let trait_items = self . tcx . trait_items ( trait_def_id) ;
647
- let maybe_item = match self . looking_for {
648
- LookingFor :: MethodName ( item_name) => {
649
- trait_items. iter ( )
650
- . find ( |item| item. name ( ) == item_name)
651
- }
652
- LookingFor :: ReturnType ( item_ty) => {
653
- trait_items. iter ( )
654
- . find ( |item| {
655
- self . fcx . matches_return_type ( item, & item_ty)
656
- } )
657
- }
658
- } ;
659
- let item = match maybe_item {
659
+ let item = match self . impl_or_trait_item ( trait_def_id) {
660
660
Some ( i) => i,
661
661
None => {
662
662
return Ok ( ( ) ) ;
663
663
}
664
664
} ;
665
665
666
666
// Check whether `trait_def_id` defines a method with suitable name:
667
- if !self . has_applicable_self ( item) {
667
+ if !self . has_applicable_self ( & item) {
668
668
debug ! ( "method has inapplicable self" ) ;
669
669
self . record_static_candidate ( TraitSource ( trait_def_id) ) ;
670
670
return Ok ( ( ) ) ;
@@ -1369,7 +1369,11 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1369
1369
self . fcx . impl_or_trait_item ( def_id, name)
1370
1370
}
1371
1371
LookingFor :: ReturnType ( return_ty) => {
1372
- self . fcx . impl_or_return_item ( def_id, return_ty)
1372
+ self . tcx
1373
+ . impl_or_trait_items ( def_id)
1374
+ . iter ( )
1375
+ . map ( |& did| self . tcx . impl_or_trait_item ( did) )
1376
+ . find ( |m| self . matches_return_type ( m, return_ty) )
1373
1377
}
1374
1378
}
1375
1379
}
0 commit comments