@@ -4595,21 +4595,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45954595 can_suggest : bool ) {
45964596 // Only suggest changing the return type for methods that
45974597 // haven't set a return type at all (and aren't `fn main()` or an impl).
4598- match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest) {
4599- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true ) => {
4598+ match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected . is_nil ( ) ) {
4599+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true , true ) => {
46004600 err. span_suggestion ( span,
46014601 "try adding a return type" ,
46024602 format ! ( "-> {} " ,
46034603 self . resolve_type_vars_with_obligations( found) ) ) ;
46044604 }
4605- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true ) => {
4605+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
46064606 err. span_label ( span, "possibly return type missing here?" ) ;
46074607 }
4608- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, _ ) => {
4608+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
46094609 // `fn main()` must return `()`, do not suggest changing return type
46104610 err. span_label ( span, "expected `()` because of default return type" ) ;
46114611 }
4612- ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _) => {
4612+ // expectation was caused by something else, not the default return
4613+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
4614+ ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
46134615 // Only point to return type if the expected type is the return type, as if they
46144616 // are not, the expectation must have been caused by something else.
46154617 debug ! ( "suggest_missing_return_type: return type {:?} node {:?}" , ty, ty. node) ;
0 commit comments