@@ -5089,12 +5089,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5089
5089
found : Ty < ' tcx > ,
5090
5090
cause_span : Span ,
5091
5091
blk_id : ast:: NodeId ,
5092
- ) {
5092
+ ) -> bool {
5093
5093
self . suggest_missing_semicolon ( err, expression, expected, cause_span) ;
5094
+ let mut pointing_at_return_type = false ;
5094
5095
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) ;
5096
5098
}
5097
5099
self . suggest_ref_or_into ( err, expression, expected, found) ;
5100
+ pointing_at_return_type
5098
5101
}
5099
5102
5100
5103
pub fn suggest_ref_or_into (
@@ -5193,12 +5196,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5193
5196
/// This routine checks if the return type is left as default, the method is not part of an
5194
5197
/// `impl` block and that it isn't the `main` method. If so, it suggests setting the return
5195
5198
/// 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 {
5202
5207
// Only suggest changing the return type for methods that
5203
5208
// haven't set a return type at all (and aren't `fn main()` or an impl).
5204
5209
match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected. is_unit ( ) ) {
@@ -5208,16 +5213,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5208
5213
"try adding a return type" ,
5209
5214
format ! ( "-> {} " , self . resolve_type_vars_with_obligations( found) ) ,
5210
5215
Applicability :: MachineApplicable ) ;
5216
+ true
5211
5217
}
5212
5218
( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
5213
5219
err. span_label ( span, "possibly return type missing here?" ) ;
5220
+ true
5214
5221
}
5215
5222
( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
5216
5223
// `fn main()` must return `()`, do not suggest changing return type
5217
5224
err. span_label ( span, "expected `()` because of default return type" ) ;
5225
+ true
5218
5226
}
5219
5227
// expectation was caused by something else, not the default return
5220
- ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
5228
+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => false ,
5221
5229
( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
5222
5230
// Only point to return type if the expected type is the return type, as if they
5223
5231
// are not, the expectation must have been caused by something else.
@@ -5229,7 +5237,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5229
5237
if ty. sty == expected. sty {
5230
5238
err. span_label ( sp, format ! ( "expected `{}` because of return type" ,
5231
5239
expected) ) ;
5240
+ return true ;
5232
5241
}
5242
+ false
5233
5243
}
5234
5244
}
5235
5245
}
0 commit comments