@@ -4625,21 +4625,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
46254625 can_suggest : bool ) {
46264626 // Only suggest changing the return type for methods that
46274627 // haven't set a return type at all (and aren't `fn main()` or an impl).
4628- match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest) {
4629- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true ) => {
4628+ match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected . is_nil ( ) ) {
4629+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true , true ) => {
46304630 err. span_suggestion ( span,
46314631 "try adding a return type" ,
46324632 format ! ( "-> {} " ,
46334633 self . resolve_type_vars_with_obligations( found) ) ) ;
46344634 }
4635- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true ) => {
4635+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
46364636 err. span_label ( span, "possibly return type missing here?" ) ;
46374637 }
4638- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, _ ) => {
4638+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
46394639 // `fn main()` must return `()`, do not suggest changing return type
46404640 err. span_label ( span, "expected `()` because of default return type" ) ;
46414641 }
4642- ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _) => {
4642+ // expectation was caused by something else, not the default return
4643+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
4644+ ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
46434645 // Only point to return type if the expected type is the return type, as if they
46444646 // are not, the expectation must have been caused by something else.
46454647 debug ! ( "suggest_missing_return_type: return type {:?} node {:?}" , ty, ty. node) ;
0 commit comments