@@ -334,23 +334,44 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
334334 prefix_path : & [ Segment ] ,
335335 path : & [ Segment ] ,
336336 ) -> Vec < ImportSuggestion > {
337- if path. len ( ) <= 1 {
338- return Vec :: new ( ) ;
337+ let next_seg = if path. len ( ) >= prefix_path. len ( ) + 1 && prefix_path. len ( ) == 1 {
338+ path. get ( prefix_path. len ( ) )
339+ } else {
340+ None
341+ } ;
342+ if let Some ( segment) = prefix_path. last ( ) &&
343+ let Some ( next_seg) = next_seg {
344+ let candidates = self . r . lookup_import_candidates (
345+ segment. ident ,
346+ Namespace :: TypeNS ,
347+ & self . parent_scope ,
348+ & |res : Res | matches ! ( res, Res :: Def ( DefKind :: Mod , _) ) ,
349+ ) ;
350+ // double check next seg is valid
351+ candidates
352+ . into_iter ( )
353+ . filter ( |candidate| {
354+ if let Some ( def_id) = candidate. did &&
355+ let Some ( module) = self . r . get_module ( def_id) {
356+ self . r . resolutions ( module) . borrow ( ) . iter ( ) . any ( |( key, _r) | {
357+ key. ident . name == next_seg. ident . name
358+ } )
359+ } else {
360+ false
361+ }
362+ } )
363+ . collect :: < Vec < _ > > ( )
364+ } else {
365+ Vec :: new ( )
339366 }
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- )
347367 }
348368
349369 /// Handles error reporting for `smart_resolve_path_fragment` function.
350370 /// Creates base error and amends it with one short label and possibly some longer helps/notes.
351371 pub ( crate ) fn smart_resolve_report_errors (
352372 & mut self ,
353373 path : & [ Segment ] ,
374+ full_path : & [ Segment ] ,
354375 span : Span ,
355376 source : PathSource < ' _ > ,
356377 res : Option < Res > ,
@@ -392,7 +413,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
392413 }
393414
394415 let ( found, candidates) =
395- self . try_lookup_name_relaxed ( & mut err, source, path, span, res, & base_error) ;
416+ self . try_lookup_name_relaxed ( & mut err, source, path, full_path , span, res, & base_error) ;
396417 if found {
397418 return ( err, candidates) ;
398419 }
@@ -498,6 +519,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
498519 err : & mut Diagnostic ,
499520 source : PathSource < ' _ > ,
500521 path : & [ Segment ] ,
522+ full_path : & [ Segment ] ,
501523 span : Span ,
502524 res : Option < Res > ,
503525 base_error : & BaseError ,
@@ -667,6 +689,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
667689 }
668690 }
669691
692+ if candidates. is_empty ( ) {
693+ candidates = self . smart_resolve_partial_mod_path_errors ( path, full_path) ;
694+ }
695+
670696 return ( false , candidates) ;
671697 }
672698
0 commit comments