Skip to content

Commit 1605488

Browse files
bors[bot]Veykril
andauthored
Merge #8947
8947: Correctly resolve crate name in use paths when import shadows it r=Veykril a=Veykril Fixes #7763 bors r+ Co-authored-by: Lukas Tobias Wirth <[email protected]>
2 parents f04daf6 + da74c66 commit 1605488

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl SourceAnalyzer {
286286
let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
287287
let hir_path = Path::from_src(path.clone(), &ctx)?;
288288

289-
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
289+
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we are
290290
// trying to resolve foo::bar.
291291
if let Some(outer_path) = parent().and_then(ast::Path::cast) {
292292
if let Some(qualifier) = outer_path.qualifier() {
@@ -295,6 +295,15 @@ impl SourceAnalyzer {
295295
}
296296
}
297297
}
298+
// Case where path is a qualifier of a use tree, e.g. foo::bar::{Baz, Qux} where we are
299+
// trying to resolve foo::bar.
300+
if let Some(use_tree) = parent().and_then(ast::UseTree::cast) {
301+
if let Some(qualifier) = use_tree.path() {
302+
if path == &qualifier && use_tree.coloncolon_token().is_some() {
303+
return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);
304+
}
305+
}
306+
}
298307

299308
resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns)
300309
}

crates/ide/src/hover.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,4 +3957,24 @@ mod string {
39573957
"#]],
39583958
)
39593959
}
3960+
3961+
#[test]
3962+
fn function_doesnt_shadow_crate_in_use_tree() {
3963+
check(
3964+
r#"
3965+
//- /main.rs crate:main deps:foo
3966+
use foo$0::{foo};
3967+
3968+
//- /foo.rs crate:foo
3969+
pub fn foo() {}
3970+
"#,
3971+
expect![[r#"
3972+
*foo*
3973+
3974+
```rust
3975+
extern crate foo
3976+
```
3977+
"#]],
3978+
)
3979+
}
39603980
}

crates/ide_assists/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub mod path_transform;
2020
use std::str::FromStr;
2121

2222
use hir::Semantics;
23-
use ide_db::base_db::FileRange;
24-
use ide_db::{label::Label, source_change::SourceChange, RootDatabase};
23+
use ide_db::{base_db::FileRange, label::Label, source_change::SourceChange, RootDatabase};
2524
use syntax::TextRange;
2625

2726
pub(crate) use crate::assist_context::{AssistContext, Assists};

0 commit comments

Comments
 (0)