@@ -4,6 +4,7 @@ use crate::late::{LifetimeBinderKind, LifetimeRes, LifetimeRibKind, LifetimeUseS
4
4
use crate :: { errors, path_names_to_string} ;
5
5
use crate :: { Module , ModuleKind , ModuleOrUniformRoot } ;
6
6
use crate :: { PathResult , PathSource , Segment } ;
7
+ use rustc_hir:: def:: Namespace :: { self , * } ;
7
8
8
9
use rustc_ast:: visit:: { FnCtxt , FnKind , LifetimeCtxt } ;
9
10
use rustc_ast:: {
@@ -17,7 +18,6 @@ use rustc_errors::{
17
18
MultiSpan ,
18
19
} ;
19
20
use rustc_hir as hir;
20
- use rustc_hir:: def:: Namespace :: { self , * } ;
21
21
use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind } ;
22
22
use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
23
23
use rustc_hir:: PrimTy ;
@@ -221,10 +221,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
221
221
let suggestion = if self . current_trait_ref . is_none ( )
222
222
&& let Some ( ( fn_kind, _) ) = self . diagnostic_metadata . current_function
223
223
&& let Some ( FnCtxt :: Assoc ( _) ) = fn_kind. ctxt ( )
224
+ && let FnKind :: Fn ( _, _, sig, ..) = fn_kind
224
225
&& let Some ( items) = self . diagnostic_metadata . current_impl_items
225
226
&& let Some ( item) = items. iter ( ) . find ( |i| {
226
227
if let AssocItemKind :: Fn ( ..) | AssocItemKind :: Const ( ..) = & i. kind
227
228
&& i. ident . name == item_str. name
229
+ // don't suggest if the item is in Fn signature arguments
230
+ // issue #112590
231
+ && !sig. span . contains ( item_span)
228
232
{
229
233
debug ! ( ?item_str. name) ;
230
234
return true
@@ -318,6 +322,30 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
318
322
}
319
323
}
320
324
325
+ /// Try to suggest for a module path that cannot be resolved.
326
+ /// Such as `fmt::Debug` where `fmt` is not resolved without importing,
327
+ /// here we search with `lookup_import_candidates` for a module named `fmt`
328
+ /// with `TypeNS` as namespace.
329
+ ///
330
+ /// We need a separate function here because we won't suggest for a path with single segment
331
+ /// and we won't change `SourcePath` api `is_expected` to match `Type` with `DefKind::Mod`
332
+ pub ( crate ) fn smart_resolve_partial_mod_path_errors (
333
+ & mut self ,
334
+ prefix_path : & [ Segment ] ,
335
+ path : & [ Segment ] ,
336
+ ) -> Vec < ImportSuggestion > {
337
+ if path. len ( ) <= 1 {
338
+ return Vec :: new ( ) ;
339
+ }
340
+ let ident = prefix_path. last ( ) . unwrap ( ) . ident ;
341
+ self . r . lookup_import_candidates (
342
+ ident,
343
+ Namespace :: TypeNS ,
344
+ & self . parent_scope ,
345
+ & |res : Res | matches ! ( res, Res :: Def ( DefKind :: Mod , _) ) ,
346
+ )
347
+ }
348
+
321
349
/// Handles error reporting for `smart_resolve_path_fragment` function.
322
350
/// Creates base error and amends it with one short label and possibly some longer helps/notes.
323
351
pub ( crate ) fn smart_resolve_report_errors (
0 commit comments