@@ -849,7 +849,7 @@ impl SourceAnalyzer {
849
849
// trying to resolve foo::bar.
850
850
if let Some ( use_tree) = parent ( ) . and_then ( ast:: UseTree :: cast) {
851
851
if use_tree. coloncolon_token ( ) . is_some ( ) {
852
- return resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map)
852
+ return resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map, None )
853
853
. map ( |it| ( it, None ) ) ;
854
854
}
855
855
}
@@ -872,9 +872,15 @@ impl SourceAnalyzer {
872
872
// Case where path is a qualifier of another path, e.g. foo::bar::Baz or foo::bar:: where we are
873
873
// trying to resolve foo::bar.
874
874
if path. parent_path ( ) . is_some ( ) || is_last_token_colon2 {
875
- let parent_hir_path =
875
+ let parent_path =
876
876
path. parent_path ( ) . and_then ( |parent_path| Path :: from_src ( & mut ctx, parent_path) ) ;
877
- return match resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map) {
877
+ return match resolve_hir_path_qualifier (
878
+ db,
879
+ & self . resolver ,
880
+ & hir_path,
881
+ & types_map,
882
+ parent_path. as_ref ( ) ,
883
+ ) {
878
884
None if meta_path. is_some ( ) => path
879
885
. first_segment ( )
880
886
. and_then ( |it| it. name_ref ( ) )
@@ -883,51 +889,6 @@ impl SourceAnalyzer {
883
889
. map ( PathResolution :: ToolModule )
884
890
} )
885
891
. map ( |it| ( it, None ) ) ,
886
- // Case the type name conflict with use module,
887
- // e.g.
888
- // ```
889
- // use std::str;
890
- // fn main() {
891
- // str::from_utf8(); // as module std::str
892
- // str::len(); // as primitive type str
893
- // str::no_exist_item(); // as primitive type str
894
- // }
895
- // ```
896
- Some ( it)
897
- if matches ! (
898
- it,
899
- PathResolution :: Def ( ModuleDef :: Adt ( _) | ModuleDef :: BuiltinType ( _) )
900
- ) =>
901
- {
902
- if let Some ( mod_path) = hir_path. mod_path ( ) {
903
- if let Some ( ModuleDefId :: ModuleId ( id) ) = self
904
- . resolver
905
- . resolve_module_path_in_items ( db. upcast ( ) , mod_path)
906
- . take_types ( )
907
- {
908
- let module = crate :: Module { id } ;
909
- let res = Some ( ( PathResolution :: Def ( ModuleDef :: Module ( module) ) , None ) ) ;
910
- match it {
911
- PathResolution :: Def ( ModuleDef :: Adt ( _) ) => return res,
912
- PathResolution :: Def ( ModuleDef :: BuiltinType ( _) ) => {
913
- if let Some ( parent_hir_path) = parent_hir_path {
914
- let parent_hir_name =
915
- parent_hir_path. segments ( ) . get ( 1 ) . map ( |it| it. name ) ;
916
- if module
917
- . scope ( db, None )
918
- . into_iter ( )
919
- . any ( |( name, _) | Some ( & name) == parent_hir_name)
920
- {
921
- return res;
922
- }
923
- }
924
- }
925
- _ => ( ) ,
926
- }
927
- }
928
- }
929
- Some ( ( it, None ) )
930
- }
931
892
// FIXME: We do not show substitutions for parts of path, because this is really complex
932
893
// due to the interactions with associated items of `impl`s and associated items of associated
933
894
// types.
@@ -1003,7 +964,7 @@ impl SourceAnalyzer {
1003
964
}
1004
965
if parent ( ) . is_some_and ( |it| ast:: Visibility :: can_cast ( it. kind ( ) ) ) {
1005
966
// No substitution because only modules can be inside visibilities, and those have no generics.
1006
- resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map)
967
+ resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map, None )
1007
968
. map ( |it| ( it, None ) )
1008
969
} else {
1009
970
// Probably a type, no need to show substitutions for those.
@@ -1550,8 +1511,9 @@ fn resolve_hir_path_qualifier(
1550
1511
resolver : & Resolver ,
1551
1512
path : & Path ,
1552
1513
types_map : & TypesMap ,
1514
+ parent_path : Option < & Path > ,
1553
1515
) -> Option < PathResolution > {
1554
- ( || {
1516
+ let resolve_from_typens = ( || {
1555
1517
let ( ty, unresolved) = match path. type_anchor ( ) {
1556
1518
Some ( type_ref) => {
1557
1519
let ( _, res) = TyLoweringContext :: new_maybe_unowned (
@@ -1617,13 +1579,40 @@ fn resolve_hir_path_qualifier(
1617
1579
. map ( PathResolution :: Def ) ,
1618
1580
None => Some ( res) ,
1619
1581
}
1620
- } ) ( )
1621
- . or_else ( || {
1582
+ } ) ( ) ;
1583
+
1584
+ let resolve_module = || {
1622
1585
resolver
1623
1586
. resolve_module_path_in_items ( db. upcast ( ) , path. mod_path ( ) ?)
1624
1587
. take_types ( )
1625
1588
. map ( |it| PathResolution :: Def ( it. into ( ) ) )
1626
- } )
1589
+ } ;
1590
+
1591
+ match resolve_from_typens {
1592
+ Some ( PathResolution :: Def ( module_def) ) => {
1593
+ let item = resolve_module ( ) ;
1594
+ if let Some ( PathResolution :: Def ( ModuleDef :: Module ( module) ) ) = item {
1595
+ match module_def {
1596
+ ModuleDef :: BuiltinType ( _) => {
1597
+ if let Some ( parent_path) = parent_path {
1598
+ let parent_name = parent_path. segments ( ) . get ( 1 ) . map ( |it| it. name ) ;
1599
+ if module
1600
+ . scope ( db, None )
1601
+ . into_iter ( )
1602
+ . any ( |( name, _) | Some ( & name) == parent_name)
1603
+ {
1604
+ return item;
1605
+ }
1606
+ }
1607
+ }
1608
+ _ => return item,
1609
+ }
1610
+ }
1611
+ resolve_from_typens
1612
+ }
1613
+ None => resolve_module ( ) ,
1614
+ Some ( _) => resolve_from_typens,
1615
+ }
1627
1616
}
1628
1617
1629
1618
pub ( crate ) fn name_hygiene ( db : & dyn HirDatabase , name : InFile < & SyntaxNode > ) -> HygieneId {
0 commit comments