@@ -4602,21 +4602,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
46024602 can_suggest : bool ) {
46034603 // Only suggest changing the return type for methods that
46044604 // haven't set a return type at all (and aren't `fn main()` or an impl).
4605- match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest) {
4606- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true ) => {
4605+ match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected . is_nil ( ) ) {
4606+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , true , true , true ) => {
46074607 err. span_suggestion ( span,
46084608 "try adding a return type" ,
46094609 format ! ( "-> {} " ,
46104610 self . resolve_type_vars_with_obligations( found) ) ) ;
46114611 }
4612- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true ) => {
4612+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
46134613 err. span_label ( span, "possibly return type missing here?" ) ;
46144614 }
4615- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, _ ) => {
4615+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
46164616 // `fn main()` must return `()`, do not suggest changing return type
46174617 err. span_label ( span, "expected `()` because of default return type" ) ;
46184618 }
4619- ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _) => {
4619+ // expectation was caused by something else, not the default return
4620+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
4621+ ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
46204622 // Only point to return type if the expected type is the return type, as if they
46214623 // are not, the expectation must have been caused by something else.
46224624 debug ! ( "suggest_missing_return_type: return type {:?} node {:?}" , ty, ty. node) ;
0 commit comments