diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-23 18:37:36 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-23 18:37:36 +0100 |
commit | 16054887102104208f4a0fc0e75e702b85a2eae8 (patch) | |
tree | 0f9f18647a70d38fc1c02761de8f4d9f16fb3283 | |
parent | f04daf693aec9f3ffbd98bd368b79646246d506b (diff) | |
parent | da74c66947ec847f2ca8e99d96cc7e36fd494c75 (diff) |
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]>
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 11 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 20 | ||||
-rw-r--r-- | crates/ide_assists/src/lib.rs | 3 |
3 files changed, 31 insertions, 3 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index b5c65808e..20753314d 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs | |||
@@ -286,7 +286,7 @@ impl SourceAnalyzer { | |||
286 | let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene); | 286 | let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene); |
287 | let hir_path = Path::from_src(path.clone(), &ctx)?; | 287 | let hir_path = Path::from_src(path.clone(), &ctx)?; |
288 | 288 | ||
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 |
290 | // trying to resolve foo::bar. | 290 | // trying to resolve foo::bar. |
291 | if let Some(outer_path) = parent().and_then(ast::Path::cast) { | 291 | if let Some(outer_path) = parent().and_then(ast::Path::cast) { |
292 | if let Some(qualifier) = outer_path.qualifier() { | 292 | if let Some(qualifier) = outer_path.qualifier() { |
@@ -295,6 +295,15 @@ impl SourceAnalyzer { | |||
295 | } | 295 | } |
296 | } | 296 | } |
297 | } | 297 | } |
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 | } | ||
298 | 307 | ||
299 | resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns) | 308 | resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns) |
300 | } | 309 | } |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 9de653739..04598cd06 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -3957,4 +3957,24 @@ mod string { | |||
3957 | "#]], | 3957 | "#]], |
3958 | ) | 3958 | ) |
3959 | } | 3959 | } |
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 | } | ||
3960 | } | 3980 | } |
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 05644b6ff..4cd82f8c1 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs | |||
@@ -20,8 +20,7 @@ pub mod path_transform; | |||
20 | use std::str::FromStr; | 20 | use std::str::FromStr; |
21 | 21 | ||
22 | use hir::Semantics; | 22 | use hir::Semantics; |
23 | use ide_db::base_db::FileRange; | 23 | use ide_db::{base_db::FileRange, label::Label, source_change::SourceChange, RootDatabase}; |
24 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; | ||
25 | use syntax::TextRange; | 24 | use syntax::TextRange; |
26 | 25 | ||
27 | pub(crate) use crate::assist_context::{AssistContext, Assists}; | 26 | pub(crate) use crate::assist_context::{AssistContext, Assists}; |