@@ -4625,21 +4625,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4625
4625
can_suggest : bool ) {
4626
4626
// Only suggest changing the return type for methods that
4627
4627
// 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 ) => {
4630
4630
err. span_suggestion ( span,
4631
4631
"try adding a return type" ,
4632
4632
format ! ( "-> {} " ,
4633
4633
self . resolve_type_vars_with_obligations( found) ) ) ;
4634
4634
}
4635
- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true ) => {
4635
+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
4636
4636
err. span_label ( span, "possibly return type missing here?" ) ;
4637
4637
}
4638
- ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, _ ) => {
4638
+ ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
4639
4639
// `fn main()` must return `()`, do not suggest changing return type
4640
4640
err. span_label ( span, "expected `()` because of default return type" ) ;
4641
4641
}
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) , _, _, _) => {
4643
4645
// Only point to return type if the expected type is the return type, as if they
4644
4646
// are not, the expectation must have been caused by something else.
4645
4647
debug ! ( "suggest_missing_return_type: return type {:?} node {:?}" , ty, ty. node) ;
0 commit comments