Repository: rust-analyzer/rust-analyzer
Pull request #11259 (2022-01-11 14:31:26)

fix: fix `use super::{super::...};`
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11249

bors r+


Patch:
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index c51201f675..0af5d654af 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -790,14 +790,26 @@ impl UseTree {
                     }
                     Some((prefix, ImportKind::Plain))
                 }
-                (Some(prefix), PathKind::Super(0)) => {
-                    // `some::path::self` == `some::path`
-                    if path.segments().is_empty() {
-                        Some((prefix, ImportKind::TypeOnly))
-                    } else {
-                        None
+                (Some(mut prefix), PathKind::Super(n))
+                    if *n > 0 && prefix.segments().is_empty() =>
+                {
+                    // `super::super` + `super::rest`
+                    match &mut prefix.kind {
+                        PathKind::Super(m) => {
+                            cov_mark::hit!(concat_super_mod_paths);
+                            *m += *n;
+                            for segment in path.segments() {
+                                prefix.push_segment(segment.clone());
+                            }
+                            Some((prefix, ImportKind::Plain))
+                        }
+                        _ => None,
                     }
                 }
+                (Some(prefix), PathKind::Super(0)) if path.segments().is_empty() => {
+                    // `some::path::self` == `some::path`
+                    Some((prefix, ImportKind::TypeOnly))
+                }
                 (Some(_), _) => None,
             }
         }
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index a549604863..13165e8d3f 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -411,9 +411,7 @@ You'll need to close and reopen all .rs and Cargo files, or to restart the IDE,
 === Kate Text Editor
 
 Support for the language server protocol is built into Kate through the LSP plugin, which is included by default.
-It is preconfigured to use rust-analyzer for Rust sources since Kate 21.12.
-
-Earlier versions allow you to use rust-analyzer through a simple settings change.
+It is preconfigured to use Rls for rust sources, but allows you to use rust-analyzer through a simple settings change.
 In the LSP Client settings of Kate, copy the content of the third tab "default parameters" to the second tab "server configuration".
 Then in the configuration replace:
 [source,json]


Test patch:
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs
index 37336ce1e9..4794932855 100644
--- a/crates/hir_def/src/nameres/tests.rs
+++ b/crates/hir_def/src/nameres/tests.rs
@@ -890,3 +890,38 @@ pub struct Struct;
         "#]],
     );
 }
+
+#[test]
+fn braced_supers_in_use_tree() {
+    cov_mark::check!(concat_super_mod_paths);
+    check(
+        r#"
+mod some_module {
+    pub fn unknown_func() {}
+}
+
+mod other_module {
+    mod some_submodule {
+        use { super::{ super::unknown_func, }, };
+    }
+}
+
+use some_module::unknown_func;
+        "#,
+        expect![[r#"
+            crate
+            other_module: t
+            some_module: t
+            unknown_func: v
+
+            crate::some_module
+            unknown_func: v
+
+            crate::other_module
+            some_submodule: t
+
+            crate::other_module::some_submodule
+            unknown_func: v
+        "#]],
+    )
+}