diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs index eacec018c72b9..158dbaf1b1dd1 100644 --- a/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs +++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs @@ -1618,3 +1618,18 @@ pub struct FooStruct; "#]], ); } + +#[test] +fn primitive_mod() { + check( + r#" +//- minicore: str +fn main() { + str::from$0 +} +"#, + expect![[r#" + fn from_utf8_unchecked(…) (use core::str) const unsafe fn(&[u8]) -> &str + "#]], + ); +} diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs index 3bb5ac1b10397..1c4c15f2557d7 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs @@ -703,7 +703,7 @@ fn path_import_candidate( ) -> Option { Some(match qualifier { Some(qualifier) => match sema.resolve_path(&qualifier) { - None => { + Some(PathResolution::Def(ModuleDef::BuiltinType(_))) | None => { if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) { let qualifier = qualifier .segments() diff --git a/src/tools/rust-analyzer/crates/ide/src/file_structure.rs b/src/tools/rust-analyzer/crates/ide/src/file_structure.rs index 568906a098e34..92458185849b4 100644 --- a/src/tools/rust-analyzer/crates/ide/src/file_structure.rs +++ b/src/tools/rust-analyzer/crates/ide/src/file_structure.rs @@ -197,7 +197,9 @@ fn structure_token(token: SyntaxToken) -> Option { if let Some(comment) = ast::Comment::cast(token) { let text = comment.text().trim(); - if let Some(region_name) = text.strip_prefix("// region:").map(str::trim) { + if let Some(region_name) = + text.strip_prefix("// region:").map(str::trim).filter(|it| !it.is_empty()) + { return Some(StructureNode { parent: None, label: region_name.to_owned(), diff --git a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs index d1862f7d738e7..2d615c34a3520 100644 --- a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs +++ b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs @@ -55,6 +55,7 @@ //! size_of: sized //! sized: //! slice: +//! str: //! sync: sized //! transmute: //! try: infallible @@ -1368,6 +1369,14 @@ pub mod iter { } // endregion:iterator +// region:str +pub mod str { + pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str { + "" + } +} +// endregion:str + // region:panic mod panic { pub macro panic_2021 {