@@ -334,23 +334,44 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
334
334
prefix_path : & [ Segment ] ,
335
335
path : & [ Segment ] ,
336
336
) -> 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 ( )
339
366
}
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
367
}
348
368
349
369
/// Handles error reporting for `smart_resolve_path_fragment` function.
350
370
/// Creates base error and amends it with one short label and possibly some longer helps/notes.
351
371
pub ( crate ) fn smart_resolve_report_errors (
352
372
& mut self ,
353
373
path : & [ Segment ] ,
374
+ full_path : & [ Segment ] ,
354
375
span : Span ,
355
376
source : PathSource < ' _ > ,
356
377
res : Option < Res > ,
@@ -392,7 +413,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
392
413
}
393
414
394
415
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) ;
396
417
if found {
397
418
return ( err, candidates) ;
398
419
}
@@ -498,6 +519,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
498
519
err : & mut Diagnostic ,
499
520
source : PathSource < ' _ > ,
500
521
path : & [ Segment ] ,
522
+ full_path : & [ Segment ] ,
501
523
span : Span ,
502
524
res : Option < Res > ,
503
525
base_error : & BaseError ,
@@ -667,6 +689,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
667
689
}
668
690
}
669
691
692
+ if candidates. is_empty ( ) {
693
+ candidates = self . smart_resolve_partial_mod_path_errors ( path, full_path) ;
694
+ }
695
+
670
696
return ( false , candidates) ;
671
697
}
672
698
0 commit comments