@@ -866,7 +866,8 @@ impl SourceAnalyzer {
866
866
867
867
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we are
868
868
// trying to resolve foo::bar.
869
- if path. parent_path ( ) . is_some ( ) {
869
+ if let Some ( parent_path) = path. parent_path ( ) {
870
+ let parent_hir_path = Path :: from_src ( & mut ctx, parent_path) ;
870
871
return match resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map) {
871
872
None if meta_path. is_some ( ) => path
872
873
. first_segment ( )
@@ -876,6 +877,47 @@ impl SourceAnalyzer {
876
877
. map ( PathResolution :: ToolModule )
877
878
} )
878
879
. map ( |it| ( it, None ) ) ,
880
+ // Case the type name conflict with use module,
881
+ // e.g.
882
+ // ```
883
+ // use std::str;
884
+ // fn main() {
885
+ // str::from_utf8(); // as module std::str
886
+ // str::len(); // as primitive type str
887
+ // str::no_exist_item(); // as primitive type str
888
+ // }
889
+ // ```
890
+ Some ( it)
891
+ if matches ! (
892
+ it,
893
+ PathResolution :: Def ( ModuleDef :: Adt ( _) | ModuleDef :: BuiltinType ( _) )
894
+ ) =>
895
+ {
896
+ if let ( Some ( mod_path) , Some ( parent_hir_path) ) =
897
+ ( hir_path. mod_path ( ) , parent_hir_path)
898
+ {
899
+ if let Some ( ModuleDefId :: ModuleId ( id) ) = self
900
+ . resolver
901
+ . resolve_module_path_in_items ( db. upcast ( ) , mod_path)
902
+ . take_types ( )
903
+ {
904
+ let parent_hir_name =
905
+ parent_hir_path. segments ( ) . get ( 1 ) . map ( |it| it. name ) ;
906
+ let module = crate :: Module { id } ;
907
+ if module
908
+ . scope ( db, None )
909
+ . into_iter ( )
910
+ . any ( |( name, _) | Some ( & name) == parent_hir_name)
911
+ {
912
+ return Some ( (
913
+ PathResolution :: Def ( ModuleDef :: Module ( module) ) ,
914
+ None ,
915
+ ) ) ;
916
+ } ;
917
+ }
918
+ }
919
+ Some ( ( it, None ) )
920
+ }
879
921
// FIXME: We do not show substitutions for parts of path, because this is really complex
880
922
// due to the interactions with associated items of `impl`s and associated items of associated
881
923
// types.
0 commit comments