@@ -1178,41 +1178,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11781178 expr : & hir:: Expr < ' _ > ,
11791179 expected : Ty < ' _ > ,
11801180 ) {
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
11821182 && 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
11851184 {
1186- ( def_id, path. segments [ 0 ] . ident , "function" )
1185+ ( def_id, path. segments [ 0 ] . ident )
11871186 } else if let hir:: ExprKind :: MethodCall ( method, ..) = expr. kind
11881187 && 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 ( ..) )
11901188 {
1191- ( def_id, method. ident , "method" )
1189+ ( def_id, method. ident )
11921190 } else {
11931191 return ;
11941192 } ;
1193+ if !matches ! ( self . tcx. def_kind( def_id) , hir:: def:: DefKind :: AssocFn | hir:: def:: DefKind :: Fn )
1194+ {
1195+ return ;
1196+ }
11951197 err. span_note (
11961198 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 ) ) ,
11981200 ) ;
11991201
12001202 if let Some ( local_did) = def_id. as_local ( )
12011203 && 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 ( )
12101206 && let ret_span = sig. decl . output . span ( )
12111207 && !ret_span. from_expansion ( )
12121208 && expected. has_concrete_skeleton ( )
12131209 {
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+ } ;
12161214 err. span_suggestion (
12171215 ret_span,
12181216 format ! ( "consider changing {ident}'s return type" ) ,
0 commit comments