@@ -866,7 +866,8 @@ impl SourceAnalyzer {
866866
867867 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we are
868868 // 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) ;
870871 return match resolve_hir_path_qualifier ( db, & self . resolver , & hir_path, & types_map) {
871872 None if meta_path. is_some ( ) => path
872873 . first_segment ( )
@@ -876,6 +877,42 @@ impl SourceAnalyzer {
876877 . map ( PathResolution :: ToolModule )
877878 } )
878879 . 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) if matches ! ( it, PathResolution :: Def ( ModuleDef :: BuiltinType ( _) ) ) => {
891+ if let ( Some ( mod_path) , Some ( parent_hir_path) ) =
892+ ( hir_path. mod_path ( ) , parent_hir_path)
893+ {
894+ if let Some ( ModuleDefId :: ModuleId ( id) ) = self
895+ . resolver
896+ . resolve_module_path_in_items ( db. upcast ( ) , mod_path)
897+ . take_types ( )
898+ {
899+ let parent_hir_name =
900+ parent_hir_path. segments ( ) . get ( 1 ) . map ( |it| it. name ) ;
901+ let module = crate :: Module { id } ;
902+ if module
903+ . scope ( db, None )
904+ . into_iter ( )
905+ . any ( |( name, _) | Some ( & name) == parent_hir_name)
906+ {
907+ return Some ( (
908+ PathResolution :: Def ( ModuleDef :: Module ( module) ) ,
909+ None ,
910+ ) ) ;
911+ } ;
912+ }
913+ }
914+ Some ( ( it, None ) )
915+ }
879916 // FIXME: We do not show substitutions for parts of path, because this is really complex
880917 // due to the interactions with associated items of `impl`s and associated items of associated
881918 // types.
0 commit comments