@@ -1178,41 +1178,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1178
1178
expr : & hir:: Expr < ' _ > ,
1179
1179
expected : Ty < ' _ > ,
1180
1180
) {
1181
- let ( def_id, ident, callee_str ) = if let hir:: ExprKind :: Call ( fun, _) = expr. kind
1181
+ let ( def_id, ident) = if let hir:: ExprKind :: Call ( fun, _) = expr. kind
1182
1182
&& let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, path) ) = fun. kind
1183
- && let hir:: def:: Res :: Def ( def_kind, def_id) = path. res
1184
- && !matches ! ( def_kind, hir:: def:: DefKind :: Ctor ( ..) )
1183
+ && let hir:: def:: Res :: Def ( _, def_id) = path. res
1185
1184
{
1186
- ( def_id, path. segments [ 0 ] . ident , "function" )
1185
+ ( def_id, path. segments [ 0 ] . ident )
1187
1186
} else if let hir:: ExprKind :: MethodCall ( method, ..) = expr. kind
1188
1187
&& let Some ( def_id) = self . typeck_results . borrow ( ) . type_dependent_def_id ( expr. hir_id )
1189
- && !matches ! ( self . tcx. def_kind( def_id) , hir:: def:: DefKind :: Ctor ( ..) )
1190
1188
{
1191
- ( def_id, method. ident , "method" )
1189
+ ( def_id, method. ident )
1192
1190
} else {
1193
1191
return ;
1194
1192
} ;
1193
+ if !matches ! ( self . tcx. def_kind( def_id) , hir:: def:: DefKind :: AssocFn | hir:: def:: DefKind :: Fn )
1194
+ {
1195
+ return ;
1196
+ }
1195
1197
err. span_note (
1196
1198
self . tcx . def_span ( def_id) ,
1197
- format ! ( "the {callee_str } {ident} is defined here" ) ,
1199
+ format ! ( "the {} {ident} is defined here" , self . tcx . def_descr ( def_id ) ) ,
1198
1200
) ;
1199
1201
1200
1202
if let Some ( local_did) = def_id. as_local ( )
1201
1203
&& let Some ( node) = self . tcx . opt_hir_node ( self . tcx . local_def_id_to_hir_id ( local_did) )
1202
- && let hir:: Node :: TraitItem ( hir:: TraitItem {
1203
- kind : hir:: TraitItemKind :: Fn ( sig, ..) ,
1204
- ..
1205
- } )
1206
- | hir:: Node :: ImplItem ( hir:: ImplItem {
1207
- kind : hir:: ImplItemKind :: Fn ( sig, ..) , ..
1208
- } )
1209
- | hir:: Node :: Item ( hir:: Item { kind : hir:: ItemKind :: Fn ( sig, ..) , .. } ) = node
1204
+ && !matches ! ( node, hir:: Node :: TraitItem ( ..) )
1205
+ && let Some ( sig) = node. fn_sig ( )
1210
1206
&& let ret_span = sig. decl . output . span ( )
1211
1207
&& !ret_span. from_expansion ( )
1212
1208
&& expected. has_concrete_skeleton ( )
1213
1209
{
1214
- let sugg =
1215
- if ret_span. is_empty ( ) { format ! ( "-> {expected}" ) } else { format ! ( "{expected}" ) } ;
1210
+ let sugg = match sig. decl . output {
1211
+ hir:: FnRetTy :: DefaultReturn ( ..) => format ! ( "-> {expected}" ) ,
1212
+ hir:: FnRetTy :: Return ( ..) => format ! ( "{expected}" ) ,
1213
+ } ;
1216
1214
err. span_suggestion (
1217
1215
ret_span,
1218
1216
format ! ( "consider changing {ident}'s return type" ) ,
0 commit comments