@@ -213,26 +213,26 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
213
213
let ( mod_prefix, mod_str, suggestion) = if path. len ( ) == 1 {
214
214
debug ! ( ?self . diagnostic_metadata. current_impl_items) ;
215
215
debug ! ( ?self . diagnostic_metadata. current_function) ;
216
- let suggestion = if let Some ( items ) = self . diagnostic_metadata . current_impl_items
216
+ let suggestion = if self . current_trait_ref . is_none ( )
217
217
&& let Some ( ( fn_kind, _) ) = self . diagnostic_metadata . current_function
218
- && self . current_trait_ref . is_none ( )
219
218
&& let Some ( FnCtxt :: Assoc ( _) ) = fn_kind. ctxt ( )
219
+ && let Some ( items) = self . diagnostic_metadata . current_impl_items
220
220
&& let Some ( item) = items. iter ( ) . find ( |i| {
221
- if let AssocItemKind :: Fn ( fn_) = & i. kind
222
- && !fn_. sig . decl . has_self ( )
223
- && i. ident . name == item_str. name
221
+ if let AssocItemKind :: Fn ( _) = & i. kind && i. ident . name == item_str. name
224
222
{
225
223
debug ! ( ?item_str. name) ;
226
- debug ! ( ?fn_. sig. decl. inputs) ;
227
224
return true
228
225
}
229
226
false
230
227
} )
228
+ && let AssocItemKind :: Fn ( fn_) = & item. kind
231
229
{
230
+ debug ! ( ?fn_) ;
231
+ let self_sugg = if fn_. sig . decl . has_self ( ) { "self." } else { "Self::" } ;
232
232
Some ( (
233
- item_span,
233
+ item_span. shrink_to_lo ( ) ,
234
234
"consider using the associated function" ,
235
- format ! ( "Self::{}" , item . ident )
235
+ self_sugg . to_string ( )
236
236
) )
237
237
} else {
238
238
None
@@ -381,11 +381,13 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
381
381
}
382
382
383
383
fn suggest_self_or_self_ref ( & mut self , err : & mut Diagnostic , path : & [ Segment ] , span : Span ) {
384
- let is_assoc_fn = self . self_type_is_available ( ) ;
384
+ if !self . self_type_is_available ( ) {
385
+ return ;
386
+ }
385
387
let Some ( path_last_segment) = path. last ( ) else { return } ;
386
388
let item_str = path_last_segment. ident ;
387
389
// Emit help message for fake-self from other languages (e.g., `this` in Javascript).
388
- if [ "this" , "my" ] . contains ( & item_str. as_str ( ) ) && is_assoc_fn {
390
+ if [ "this" , "my" ] . contains ( & item_str. as_str ( ) ) {
389
391
err. span_suggestion_short (
390
392
span,
391
393
"you might have meant to use `self` here instead" ,
@@ -436,7 +438,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
436
438
let is_enum_variant = & |res| matches ! ( res, Res :: Def ( DefKind :: Variant , _) ) ;
437
439
let path_str = Segment :: names_to_string ( path) ;
438
440
let ident_span = path. last ( ) . map_or ( span, |ident| ident. ident . span ) ;
439
-
440
441
let mut candidates = self
441
442
. r
442
443
. lookup_import_candidates ( ident, ns, & self . parent_scope , is_expected)
@@ -1512,7 +1513,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
1512
1513
_ => None ,
1513
1514
}
1514
1515
}
1515
-
1516
1516
// Fields are generally expected in the same contexts as locals.
1517
1517
if filter_fn ( Res :: Local ( ast:: DUMMY_NODE_ID ) ) {
1518
1518
if let Some ( node_id) =
0 commit comments