@@ -5089,12 +5089,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50895089 found : Ty < ' tcx > ,
50905090 cause_span : Span ,
50915091 blk_id : ast:: NodeId ,
5092- ) {
5092+ ) -> bool {
50935093 self . suggest_missing_semicolon ( err, expression, expected, cause_span) ;
5094+ let mut pointing_at_return_type = false ;
50945095 if let Some ( ( fn_decl, can_suggest) ) = self . get_fn_decl ( blk_id) {
5095- self . suggest_missing_return_type ( err, & fn_decl, expected, found, can_suggest) ;
5096+ pointing_at_return_type = self . suggest_missing_return_type (
5097+ err, & fn_decl, expected, found, can_suggest) ;
50965098 }
50975099 self . suggest_ref_or_into ( err, expression, expected, found) ;
5100+ pointing_at_return_type
50985101 }
50995102
51005103 pub fn suggest_ref_or_into (
@@ -5193,12 +5196,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
51935196 /// This routine checks if the return type is left as default, the method is not part of an
51945197 /// `impl` block and that it isn't the `main` method. If so, it suggests setting the return
51955198 /// type.
5196- fn suggest_missing_return_type ( & self ,
5197- err : & mut DiagnosticBuilder < ' tcx > ,
5198- fn_decl : & hir:: FnDecl ,
5199- expected : Ty < ' tcx > ,
5200- found : Ty < ' tcx > ,
5201- can_suggest : bool ) {
5199+ fn suggest_missing_return_type (
5200+ & self ,
5201+ err : & mut DiagnosticBuilder < ' tcx > ,
5202+ fn_decl : & hir:: FnDecl ,
5203+ expected : Ty < ' tcx > ,
5204+ found : Ty < ' tcx > ,
5205+ can_suggest : bool ,
5206+ ) -> bool {
52025207 // Only suggest changing the return type for methods that
52035208 // haven't set a return type at all (and aren't `fn main()` or an impl).
52045209 match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected. is_unit ( ) ) {
@@ -5208,16 +5213,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52085213 "try adding a return type" ,
52095214 format ! ( "-> {} " , self . resolve_type_vars_with_obligations( found) ) ,
52105215 Applicability :: MachineApplicable ) ;
5216+ true
52115217 }
52125218 ( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
52135219 err. span_label ( span, "possibly return type missing here?" ) ;
5220+ true
52145221 }
52155222 ( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
52165223 // `fn main()` must return `()`, do not suggest changing return type
52175224 err. span_label ( span, "expected `()` because of default return type" ) ;
5225+ true
52185226 }
52195227 // expectation was caused by something else, not the default return
5220- ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
5228+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => false ,
52215229 ( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
52225230 // Only point to return type if the expected type is the return type, as if they
52235231 // are not, the expectation must have been caused by something else.
@@ -5229,7 +5237,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52295237 if ty. sty == expected. sty {
52305238 err. span_label ( sp, format ! ( "expected `{}` because of return type" ,
52315239 expected) ) ;
5240+ return true ;
52325241 }
5242+ false
52335243 }
52345244 }
52355245 }
0 commit comments