@@ -52,9 +52,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5252 }
5353 let mut pointing_at_return_type = false ;
5454 if let Some ( ( fn_decl, can_suggest) ) = self . get_fn_decl ( blk_id) {
55- pointing_at_return_type =
56- self . suggest_missing_return_type ( err, & fn_decl, expected, found, can_suggest) ;
5755 let fn_id = self . tcx . hir ( ) . get_return_block ( blk_id) . unwrap ( ) ;
56+ pointing_at_return_type = self . suggest_missing_return_type (
57+ err,
58+ & fn_decl,
59+ expected,
60+ found,
61+ can_suggest,
62+ fn_id,
63+ ) ;
5864 self . suggest_missing_break_or_return_expr (
5965 err, expr, & fn_decl, expected, found, blk_id, fn_id,
6066 ) ;
@@ -433,6 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
433439 expected : Ty < ' tcx > ,
434440 found : Ty < ' tcx > ,
435441 can_suggest : bool ,
442+ fn_id : hir:: HirId ,
436443 ) -> bool {
437444 // Only suggest changing the return type for methods that
438445 // haven't set a return type at all (and aren't `fn main()` or an impl).
@@ -465,7 +472,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
465472 let ty = <dyn AstConv < ' _ > >:: ast_ty_to_ty ( self , ty) ;
466473 debug ! ( "suggest_missing_return_type: return type {:?}" , ty) ;
467474 debug ! ( "suggest_missing_return_type: expected type {:?}" , ty) ;
468- if ty. kind ( ) == expected. kind ( ) {
475+ let bound_vars = self . tcx . late_bound_vars ( fn_id) ;
476+ let ty = self . tcx . erase_late_bound_regions ( Binder :: bind_with_vars ( ty, bound_vars) ) ;
477+ let ty = self . normalize_associated_types_in ( sp, ty) ;
478+ if self . can_coerce ( expected, ty) {
469479 err. span_label ( sp, format ! ( "expected `{}` because of return type" , expected) ) ;
470480 return true ;
471481 }
0 commit comments