about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-23 17:37:36 +0000
committerGitHub <noreply@github.com>2021-05-23 17:37:36 +0000
commit16054887102104208f4a0fc0e75e702b85a2eae8 (patch)
tree0f9f18647a70d38fc1c02761de8f4d9f16fb3283
parentf04daf693aec9f3ffbd98bd368b79646246d506b (diff)
parentda74c66947ec847f2ca8e99d96cc7e36fd494c75 (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 <lukastw97@gmail.com>
-rw-r--r--crates/hir/src/source_analyzer.rs11
-rw-r--r--crates/ide/src/hover.rs20
-rw-r--r--crates/ide_assists/src/lib.rs3
3 files changed, 31 insertions, 3 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index b5c65808e60..20753314dad 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -286,7 +286,7 @@ impl SourceAnalyzer {
         let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
         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.
         if let Some(outer_path) = parent().and_then(ast::Path::cast) {
             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)
     }
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 9de65373995..04598cd068c 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -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
+                ```
+            "#]],
+        )
+    }
 }
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs
index 05644b6ff5c..4cd82f8c16d 100644
--- a/crates/ide_assists/src/lib.rs
+++ b/crates/ide_assists/src/lib.rs
@@ -20,8 +20,7 @@ pub mod path_transform;
 use std::str::FromStr;
 
 use hir::Semantics;
-use ide_db::base_db::FileRange;
-use ide_db::{label::Label, source_change::SourceChange, RootDatabase};
+use ide_db::{base_db::FileRange, label::Label, source_change::SourceChange, RootDatabase};
 use syntax::TextRange;
 
 pub(crate) use crate::assist_context::{AssistContext, Assists};