@@ -5081,12 +5081,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5081
5081
found : Ty < ' tcx > ,
5082
5082
cause_span : Span ,
5083
5083
blk_id : ast:: NodeId ,
5084
- ) {
5084
+ ) -> bool {
5085
5085
self . suggest_missing_semicolon ( err, expression, expected, cause_span) ;
5086
+ let mut pointing_at_return_type = false ;
5086
5087
if let Some ( ( fn_decl, can_suggest) ) = self . get_fn_decl ( blk_id) {
5087
- self . suggest_missing_return_type ( err, & fn_decl, expected, found, can_suggest) ;
5088
+ pointing_at_return_type = self . suggest_missing_return_type (
5089
+ err, & fn_decl, expected, found, can_suggest) ;
5088
5090
}
5089
5091
self . suggest_ref_or_into ( err, expression, expected, found) ;
5092
+ pointing_at_return_type
5090
5093
}
5091
5094
5092
5095
pub fn suggest_ref_or_into (
@@ -5185,12 +5188,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5185
5188
/// This routine checks if the return type is left as default, the method is not part of an
5186
5189
/// `impl` block and that it isn't the `main` method. If so, it suggests setting the return
5187
5190
/// type.
5188
- fn suggest_missing_return_type ( & self ,
5189
- err : & mut DiagnosticBuilder < ' tcx > ,
5190
- fn_decl : & hir:: FnDecl ,
5191
- expected : Ty < ' tcx > ,
5192
- found : Ty < ' tcx > ,
5193
- can_suggest : bool ) {
5191
+ fn suggest_missing_return_type (
5192
+ & self ,
5193
+ err : & mut DiagnosticBuilder < ' tcx > ,
5194
+ fn_decl : & hir:: FnDecl ,
5195
+ expected : Ty < ' tcx > ,
5196
+ found : Ty < ' tcx > ,
5197
+ can_suggest : bool ,
5198
+ ) -> bool {
5194
5199
// Only suggest changing the return type for methods that
5195
5200
// haven't set a return type at all (and aren't `fn main()` or an impl).
5196
5201
match ( & fn_decl. output , found. is_suggestable ( ) , can_suggest, expected. is_unit ( ) ) {
@@ -5200,16 +5205,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5200
5205
"try adding a return type" ,
5201
5206
format ! ( "-> {} " , self . resolve_type_vars_with_obligations( found) ) ,
5202
5207
Applicability :: MachineApplicable ) ;
5208
+ true
5203
5209
}
5204
5210
( & hir:: FunctionRetTy :: DefaultReturn ( span) , false , true , true ) => {
5205
5211
err. span_label ( span, "possibly return type missing here?" ) ;
5212
+ true
5206
5213
}
5207
5214
( & hir:: FunctionRetTy :: DefaultReturn ( span) , _, false , true ) => {
5208
5215
// `fn main()` must return `()`, do not suggest changing return type
5209
5216
err. span_label ( span, "expected `()` because of default return type" ) ;
5217
+ true
5210
5218
}
5211
5219
// expectation was caused by something else, not the default return
5212
- ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => { }
5220
+ ( & hir:: FunctionRetTy :: DefaultReturn ( _) , _, _, false ) => false ,
5213
5221
( & hir:: FunctionRetTy :: Return ( ref ty) , _, _, _) => {
5214
5222
// Only point to return type if the expected type is the return type, as if they
5215
5223
// are not, the expectation must have been caused by something else.
@@ -5221,7 +5229,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5221
5229
if ty. sty == expected. sty {
5222
5230
err. span_label ( sp, format ! ( "expected `{}` because of return type" ,
5223
5231
expected) ) ;
5232
+ return true ;
5224
5233
}
5234
+ false
5225
5235
}
5226
5236
}
5227
5237
}
0 commit comments