@@ -521,6 +521,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
521
521
}
522
522
}
523
523
524
+ fn note_possible_function_call ( & self ,
525
+ diag : & mut DiagnosticBuilder < ' tcx > ,
526
+ values : Option < ValuePairs < ' tcx > > ,
527
+ span : Span )
528
+ {
529
+ if let Some ( infer:: Types ( ty:: error:: ExpectedFound {
530
+ expected, found
531
+ } ) ) = values {
532
+ let ( def_id, ret_ty) = match found. sty {
533
+ ty:: TyFnDef ( def, _, fty) => ( Some ( def) , fty. sig . output ( ) ) ,
534
+ ty:: TyFnPtr ( fty) => ( None , fty. sig . output ( ) ) ,
535
+ _ => return
536
+ } ;
537
+
538
+ let ok = self . probe ( |_| {
539
+ match self . replace_late_bound_regions_with_fresh_var (
540
+ span,
541
+ super :: LateBoundRegionConversionTime :: HigherRankedType ,
542
+ & ret_ty)
543
+ {
544
+ ( ty:: FnConverging ( ret_ty) , _) => {
545
+ self . can_equate ( & ret_ty, & expected) . is_ok ( )
546
+ }
547
+ ( ty:: FnDiverging , _) => true
548
+ }
549
+ } ) ;
550
+
551
+ if ok {
552
+ let message = match def_id {
553
+ Some ( def_id) => {
554
+ format ! ( "`{}` is a function" , self . tcx. item_path_str( def_id) )
555
+ }
556
+ _ => format ! ( "found a function" )
557
+ } ;
558
+ diag. help ( & format ! ( "{} - maybe try calling it?" , message) ) ;
559
+ }
560
+ }
561
+ }
562
+
524
563
pub fn note_type_err ( & self ,
525
564
diag : & mut DiagnosticBuilder < ' tcx > ,
526
565
origin : TypeOrigin ,
@@ -529,7 +568,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
529
568
{
530
569
let expected_found = match values {
531
570
None => None ,
532
- Some ( values) => match self . values_str ( & values) {
571
+ Some ( ref values) => match self . values_str ( values) {
533
572
Some ( ( expected, found) ) => Some ( ( expected, found) ) ,
534
573
None => {
535
574
// Derived error. Cancel the emitter.
@@ -563,6 +602,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
563
602
564
603
self . note_error_origin ( diag, & origin) ;
565
604
self . check_and_note_conflicting_crates ( diag, terr, span) ;
605
+ self . note_possible_function_call ( diag, values, span) ;
566
606
self . tcx . note_and_explain_type_err ( diag, terr, span) ;
567
607
}
568
608
0 commit comments