@@ -214,6 +214,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
214
214
module : None ,
215
215
}
216
216
} else {
217
+ let mut span_label = None ;
217
218
let item_span = path. last ( ) . unwrap ( ) . ident . span ;
218
219
let ( mod_prefix, mod_str, module, suggestion) = if path. len ( ) == 1 {
219
220
debug ! ( ?self . diagnostic_metadata. current_impl_items) ;
@@ -224,39 +225,36 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
224
225
&& let FnKind :: Fn ( _, _, sig, ..) = fn_kind
225
226
&& let Some ( items) = self . diagnostic_metadata . current_impl_items
226
227
&& let Some ( item) = items. iter ( ) . find ( |i| {
227
- if i. ident . name == item_str. name
228
+ i. ident . name == item_str. name
228
229
// Don't suggest if the item is in Fn signature arguments (#112590).
229
230
&& !sig. span . contains ( item_span)
230
- {
231
- debug ! ( ?item_str. name) ;
232
- return match & i. kind {
233
- AssocItemKind :: Fn ( fn_)
234
- if !sig. decl . has_self ( ) && fn_. sig . decl . has_self ( ) => {
235
- // Ensure that we only suggest `self.` if `self` is available,
236
- // you can't call `fn foo(&self)` from `fn bar()` (#115992).
237
- false
238
- }
239
- AssocItemKind :: Fn ( _) | AssocItemKind :: Const ( ..) => true ,
240
- _ => false
241
- }
242
- }
243
- false
244
231
} )
245
232
{
246
- let self_sugg = match & item. kind {
247
- AssocItemKind :: Fn ( fn_) if fn_. sig . decl . has_self ( ) => "self." ,
248
- _ => "Self::" ,
249
- } ;
250
-
251
- Some ( (
252
- item_span. shrink_to_lo ( ) ,
253
- match & item. kind {
254
- AssocItemKind :: Fn ( ..) => "consider using the associated function" ,
255
- AssocItemKind :: Const ( ..) => "consider using the associated constant" ,
256
- _ => unreachable ! ( "item kind was filtered above" ) ,
257
- } ,
258
- self_sugg. to_string ( )
259
- ) )
233
+ let sp = item_span. shrink_to_lo ( ) ;
234
+ match & item. kind {
235
+ AssocItemKind :: Fn ( fn_)
236
+ if !sig. decl . has_self ( ) && fn_. sig . decl . has_self ( ) => {
237
+ // Ensure that we only suggest `self.` if `self` is available,
238
+ // you can't call `fn foo(&self)` from `fn bar()` (#115992).
239
+ // We also want to mention that the method exists.
240
+ span_label = Some ( (
241
+ item. ident . span ,
242
+ "a method by that name is available on `Self` here" ,
243
+ ) ) ;
244
+ None
245
+ }
246
+ AssocItemKind :: Fn ( fn_) => Some ( (
247
+ sp,
248
+ "consider using the associated function" ,
249
+ if fn_. sig . decl . has_self ( ) { "self." } else { "Self::" } ,
250
+ ) ) ,
251
+ AssocItemKind :: Const ( ..) => Some ( (
252
+ sp,
253
+ "consider using the associated constant" ,
254
+ "Self::" ,
255
+ ) ) ,
256
+ _ => None
257
+ }
260
258
} else {
261
259
None
262
260
} ;
@@ -321,7 +319,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
321
319
msg : format ! ( "cannot find {expected} `{item_str}` in {mod_prefix}{mod_str}" ) ,
322
320
fallback_label,
323
321
span : item_span,
324
- span_label : None ,
322
+ span_label,
325
323
could_be_expr : false ,
326
324
suggestion,
327
325
module,
0 commit comments