@@ -21,7 +21,8 @@ use rustc::ty::subst::{Subst, Substs};
21
21
use rustc:: traits:: { self , ObligationCause } ;
22
22
use rustc:: ty:: { self , Ty , ToPolyTraitRef , TraitRef , TypeFoldable } ;
23
23
use rustc:: infer:: type_variable:: TypeVariableOrigin ;
24
- use rustc:: util:: nodemap:: FxHashSet ;
24
+ use rustc:: util:: nodemap:: { FnvHashSet , FxHashSet } ;
25
+ use rustc:: infer:: { self , InferOk , TypeOrigin } ;
25
26
use syntax:: ast;
26
27
use syntax_pos:: Span ;
27
28
use rustc:: hir;
@@ -626,27 +627,27 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
626
627
Ok ( ( ) )
627
628
}
628
629
630
+ pub fn matches_return_type ( & self , method : & ty:: ImplOrTraitItem < ' tcx > ,
631
+ expected : ty:: Ty < ' tcx > ) -> bool {
632
+ match * method {
633
+ ty:: ImplOrTraitItem :: MethodTraitItem ( ref x) => {
634
+ self . probe ( |_| {
635
+ let output = self . replace_late_bound_regions_with_fresh_var (
636
+ self . span , infer:: FnCall , & x. fty . sig . output ( ) ) ;
637
+ self . can_sub_types ( output. 0 , expected) . is_ok ( )
638
+ } )
639
+ }
640
+ _ => false ,
641
+ }
642
+ }
643
+
629
644
fn assemble_extension_candidates_for_trait ( & mut self ,
630
645
trait_def_id : DefId )
631
646
-> Result < ( ) , MethodError < ' tcx > > {
632
647
debug ! ( "assemble_extension_candidates_for_trait(trait_def_id={:?})" ,
633
648
trait_def_id) ;
634
649
635
- // Check whether `trait_def_id` defines a method with suitable name:
636
- let trait_items = self . tcx . associated_items ( trait_def_id) ;
637
- let maybe_item = match self . looking_for {
638
- LookingFor :: MethodName ( item_name) => {
639
- trait_items. iter ( )
640
- . find ( |item| item. name == item_name)
641
- }
642
- LookingFor :: ReturnType ( item_ty) => {
643
- trait_items. iter ( )
644
- . find ( |item| {
645
- self . fcx . matches_return_type ( item, & item_ty)
646
- } )
647
- }
648
- } ;
649
- let item = match maybe_item {
650
+ let item = match self . impl_or_trait_item ( trait_def_id) {
650
651
Some ( i) => i,
651
652
None => {
652
653
return Ok ( ( ) ) ;
@@ -1351,7 +1352,11 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1351
1352
self . fcx . impl_or_trait_item ( def_id, name)
1352
1353
}
1353
1354
LookingFor :: ReturnType ( return_ty) => {
1354
- self . fcx . impl_or_return_item ( def_id, return_ty)
1355
+ self . tcx
1356
+ . impl_or_trait_items ( def_id)
1357
+ . iter ( )
1358
+ . map ( |& did| self . tcx . impl_or_trait_item ( did) )
1359
+ . find ( |m| self . matches_return_type ( m, return_ty) )
1355
1360
}
1356
1361
}
1357
1362
}
0 commit comments