@@ -4595,21 +4595,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4595
4595
can_suggest : bool ) {
4596
4596
// Only suggest changing the return type for methods that
4597
4597
// 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 ) => {
4600
4600
err. span_suggestion ( span,
4601
4601
"try adding a return type" ,
4602
4602
format ! ( "-> {} " ,
4603
4603
self . resolve_type_vars_with_obligations( found) ) ) ;
4604
4604
}
4605
- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true ) => {
4605
+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
4606
4606
err. span_label ( span, "possibly return type missing here?" ) ;
4607
4607
}
4608
- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, _ ) => {
4608
+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
4609
4609
// `fn main()` must return `()`, do not suggest changing return type
4610
4610
err. span_label ( span, "expected `()` because of default return type" ) ;
4611
4611
}
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) , _, _, _) => {
4613
4615
// Only point to return type if the expected type is the return type, as if they
4614
4616
// are not, the expectation must have been caused by something else.
4615
4617
debug ! ( "suggest_missing_return_type: return type {:?} node {:?}" , ty, ty. node) ;
0 commit comments