@@ -52,9 +52,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
52
52
}
53
53
let mut pointing_at_return_type = false ;
54
54
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) ;
57
55
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
+ ) ;
58
64
self . suggest_missing_break_or_return_expr (
59
65
err, expr, & fn_decl, expected, found, blk_id, fn_id,
60
66
) ;
@@ -433,6 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
433
439
expected : Ty < ' tcx > ,
434
440
found : Ty < ' tcx > ,
435
441
can_suggest : bool ,
442
+ fn_id : hir:: HirId ,
436
443
) -> bool {
437
444
// Only suggest changing the return type for methods that
438
445
// 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> {
465
472
let ty = <dyn AstConv < ' _ > >:: ast_ty_to_ty ( self , ty) ;
466
473
debug ! ( "suggest_missing_return_type: return type {:?}" , ty) ;
467
474
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) {
469
479
err. span_label ( sp, format ! ( "expected `{}` because of return type" , expected) ) ;
470
480
return true ;
471
481
}
0 commit comments