@@ -219,26 +219,26 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
219
219
let ( mod_prefix, mod_str, suggestion) = if path. len ( ) == 1 {
220
220
debug ! ( ?self . diagnostic_metadata. current_impl_items) ;
221
221
debug ! ( ?self . diagnostic_metadata. current_function) ;
222
- let suggestion = if let Some ( items ) = self . diagnostic_metadata . current_impl_items
222
+ let suggestion = if self . current_trait_ref . is_none ( )
223
223
&& let Some ( ( fn_kind, _) ) = self . diagnostic_metadata . current_function
224
- && self . current_trait_ref . is_none ( )
225
224
&& let Some ( FnCtxt :: Assoc ( _) ) = fn_kind. ctxt ( )
225
+ && let Some ( items) = self . diagnostic_metadata . current_impl_items
226
226
&& let Some ( item) = items. iter ( ) . find ( |i| {
227
- if let AssocItemKind :: Fn ( fn_) = & i. kind
228
- && !fn_. sig . decl . has_self ( )
229
- && i. ident . name == item_str. name
227
+ if let AssocItemKind :: Fn ( _) = & i. kind && i. ident . name == item_str. name
230
228
{
231
229
debug ! ( ?item_str. name) ;
232
- debug ! ( ?fn_. sig. decl. inputs) ;
233
230
return true
234
231
}
235
232
false
236
233
} )
234
+ && let AssocItemKind :: Fn ( fn_) = & item. kind
237
235
{
236
+ debug ! ( ?fn_) ;
237
+ let self_sugg = if fn_. sig . decl . has_self ( ) { "self." } else { "Self::" } ;
238
238
Some ( (
239
- item_span,
239
+ item_span. shrink_to_lo ( ) ,
240
240
"consider using the associated function" ,
241
- format ! ( "Self::{}" , item . ident )
241
+ self_sugg . to_string ( )
242
242
) )
243
243
} else {
244
244
None
@@ -396,11 +396,13 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
396
396
}
397
397
398
398
fn suggest_self_or_self_ref ( & mut self , err : & mut Diagnostic , path : & [ Segment ] , span : Span ) {
399
- let is_assoc_fn = self . self_type_is_available ( ) ;
399
+ if !self . self_type_is_available ( ) {
400
+ return ;
401
+ }
400
402
let Some ( path_last_segment) = path. last ( ) else { return } ;
401
403
let item_str = path_last_segment. ident ;
402
404
// Emit help message for fake-self from other languages (e.g., `this` in Javascript).
403
- if [ "this" , "my" ] . contains ( & item_str. as_str ( ) ) && is_assoc_fn {
405
+ if [ "this" , "my" ] . contains ( & item_str. as_str ( ) ) {
404
406
err. span_suggestion_short (
405
407
span,
406
408
"you might have meant to use `self` here instead" ,
@@ -451,7 +453,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
451
453
let is_enum_variant = & |res| matches ! ( res, Res :: Def ( DefKind :: Variant , _) ) ;
452
454
let path_str = Segment :: names_to_string ( path) ;
453
455
let ident_span = path. last ( ) . map_or ( span, |ident| ident. ident . span ) ;
454
-
455
456
let mut candidates = self
456
457
. r
457
458
. lookup_import_candidates ( ident, ns, & self . parent_scope , is_expected)
@@ -1542,7 +1543,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
1542
1543
_ => None ,
1543
1544
}
1544
1545
}
1545
-
1546
1546
// Fields are generally expected in the same contexts as locals.
1547
1547
if filter_fn ( Res :: Local ( ast:: DUMMY_NODE_ID ) ) {
1548
1548
if let Some ( node_id) =
0 commit comments