@@ -4,6 +4,7 @@ use crate::late::{LifetimeBinderKind, LifetimeRes, LifetimeRibKind, LifetimeUseS
44use crate :: { errors, path_names_to_string} ;
55use crate :: { Module , ModuleKind , ModuleOrUniformRoot } ;
66use crate :: { PathResult , PathSource , Segment } ;
7+ use rustc_hir:: def:: Namespace :: { self , * } ;
78
89use rustc_ast:: visit:: { FnCtxt , FnKind , LifetimeCtxt } ;
910use rustc_ast:: {
@@ -17,7 +18,6 @@ use rustc_errors::{
1718 MultiSpan ,
1819} ;
1920use rustc_hir as hir;
20- use rustc_hir:: def:: Namespace :: { self , * } ;
2121use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind } ;
2222use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
2323use rustc_hir:: PrimTy ;
@@ -221,10 +221,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
221221 let suggestion = if self . current_trait_ref . is_none ( )
222222 && let Some ( ( fn_kind, _) ) = self . diagnostic_metadata . current_function
223223 && let Some ( FnCtxt :: Assoc ( _) ) = fn_kind. ctxt ( )
224+ && let FnKind :: Fn ( _, _, sig, ..) = fn_kind
224225 && let Some ( items) = self . diagnostic_metadata . current_impl_items
225226 && let Some ( item) = items. iter ( ) . find ( |i| {
226227 if let AssocItemKind :: Fn ( ..) | AssocItemKind :: Const ( ..) = & i. kind
227228 && 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)
228232 {
229233 debug ! ( ?item_str. name) ;
230234 return true
@@ -318,6 +322,30 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
318322 }
319323 }
320324
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+
321349 /// Handles error reporting for `smart_resolve_path_fragment` function.
322350 /// Creates base error and amends it with one short label and possibly some longer helps/notes.
323351 pub ( crate ) fn smart_resolve_report_errors (
0 commit comments