mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Correctly resolve crate name in use paths when import shadows itself
This commit is contained in:
parent
f04daf693a
commit
da74c66947
@ -286,7 +286,7 @@ impl SourceAnalyzer {
|
|||||||
let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
|
let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
|
||||||
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
||||||
|
|
||||||
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
|
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we are
|
||||||
// trying to resolve foo::bar.
|
// trying to resolve foo::bar.
|
||||||
if let Some(outer_path) = parent().and_then(ast::Path::cast) {
|
if let Some(outer_path) = parent().and_then(ast::Path::cast) {
|
||||||
if let Some(qualifier) = outer_path.qualifier() {
|
if let Some(qualifier) = outer_path.qualifier() {
|
||||||
@ -295,6 +295,15 @@ impl SourceAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Case where path is a qualifier of a use tree, e.g. foo::bar::{Baz, Qux} where we are
|
||||||
|
// trying to resolve foo::bar.
|
||||||
|
if let Some(use_tree) = parent().and_then(ast::UseTree::cast) {
|
||||||
|
if let Some(qualifier) = use_tree.path() {
|
||||||
|
if path == &qualifier && use_tree.coloncolon_token().is_some() {
|
||||||
|
return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns)
|
resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns)
|
||||||
}
|
}
|
||||||
|
@ -3957,4 +3957,24 @@ mod string {
|
|||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn function_doesnt_shadow_crate_in_use_tree() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:foo
|
||||||
|
use foo$0::{foo};
|
||||||
|
|
||||||
|
//- /foo.rs crate:foo
|
||||||
|
pub fn foo() {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*foo*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
extern crate foo
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,7 @@ pub mod path_transform;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ide_db::base_db::FileRange;
|
use ide_db::{base_db::FileRange, label::Label, source_change::SourceChange, RootDatabase};
|
||||||
use ide_db::{label::Label, source_change::SourceChange, RootDatabase};
|
|
||||||
use syntax::TextRange;
|
use syntax::TextRange;
|
||||||
|
|
||||||
pub(crate) use crate::assist_context::{AssistContext, Assists};
|
pub(crate) use crate::assist_context::{AssistContext, Assists};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user