Skip to content

Commit fba8f7c

Browse files
committed
Auto merge of rust-lang#17656 - Veykril:flyimport-builtin-mod, r=Veykril
fix: Allow flyimport to import primitive shadowing modules Fixes rust-lang/rust-analyzer#16371
2 parents 042745c + 66ed952 commit fba8f7c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/tests/flyimport.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,3 +1618,18 @@ pub struct FooStruct;
16181618
"#]],
16191619
);
16201620
}
1621+
1622+
#[test]
1623+
fn primitive_mod() {
1624+
check(
1625+
r#"
1626+
//- minicore: str
1627+
fn main() {
1628+
str::from$0
1629+
}
1630+
"#,
1631+
expect![[r#"
1632+
fn from_utf8_unchecked(…) (use core::str) const unsafe fn(&[u8]) -> &str
1633+
"#]],
1634+
);
1635+
}

src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ fn path_import_candidate(
703703
) -> Option<ImportCandidate> {
704704
Some(match qualifier {
705705
Some(qualifier) => match sema.resolve_path(&qualifier) {
706-
None => {
706+
Some(PathResolution::Def(ModuleDef::BuiltinType(_))) | None => {
707707
if qualifier.first_qualifier().map_or(true, |it| sema.resolve_path(&it).is_none()) {
708708
let qualifier = qualifier
709709
.segments()

src/tools/rust-analyzer/crates/ide/src/file_structure.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ fn structure_token(token: SyntaxToken) -> Option<StructureNode> {
197197
if let Some(comment) = ast::Comment::cast(token) {
198198
let text = comment.text().trim();
199199

200-
if let Some(region_name) = text.strip_prefix("// region:").map(str::trim) {
200+
if let Some(region_name) =
201+
text.strip_prefix("// region:").map(str::trim).filter(|it| !it.is_empty())
202+
{
201203
return Some(StructureNode {
202204
parent: None,
203205
label: region_name.to_owned(),

src/tools/rust-analyzer/crates/test-utils/src/minicore.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
//! size_of: sized
5656
//! sized:
5757
//! slice:
58+
//! str:
5859
//! sync: sized
5960
//! transmute:
6061
//! try: infallible
@@ -1368,6 +1369,14 @@ pub mod iter {
13681369
}
13691370
// endregion:iterator
13701371

1372+
// region:str
1373+
pub mod str {
1374+
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
1375+
""
1376+
}
1377+
}
1378+
// endregion:str
1379+
13711380
// region:panic
13721381
mod panic {
13731382
pub macro panic_2021 {

0 commit comments

Comments
 (0)