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