]> git.lizzy.rs Git - rust.git/commitdiff
Don't qualify self as crate in add_missing_impl_members assist
authorLukas Wirth <lukastw97@gmail.com>
Tue, 27 Jul 2021 17:29:47 +0000 (19:29 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Tue, 27 Jul 2021 17:29:47 +0000 (19:29 +0200)
crates/ide_assists/src/handlers/add_missing_impl_members.rs
crates/ide_db/src/path_transform.rs

index 8225ae22c6a58b6929ac738b404b958ed0a9933c..59d5f48301b5537e3f84b3b574272ebfc85235d2 100644 (file)
@@ -812,4 +812,39 @@ fn foo(&self, bar: BAR) {
 "#,
         )
     }
+
+    #[test]
+    fn does_not_requalify_self_as_crate() {
+        check_assist(
+            add_missing_default_members,
+            r"
+struct Wrapper<T>(T);
+
+trait T {
+    fn f(self) -> Wrapper<Self> {
+        Wrapper(self)
+    }
+}
+
+impl T for () {
+    $0
+}
+",
+            r"
+struct Wrapper<T>(T);
+
+trait T {
+    fn f(self) -> Wrapper<Self> {
+        Wrapper(self)
+    }
+}
+
+impl T for () {
+    $0fn f(self) -> Wrapper<Self> {
+        Wrapper(self)
+    }
+}
+",
+        );
+    }
 }
index f3d7aa920c09ac8dff31548cae271dc8939df1ff..32eb98714b1be36d4e93b436c1de4f6c8eebd820 100644 (file)
@@ -101,8 +101,11 @@ fn transform_path(&self, path: ast::Path) -> Option<()> {
         if path.qualifier().is_some() {
             return None;
         }
-        if path.segment().and_then(|s| s.param_list()).is_some() {
+        if path.segment().map_or(false, |s| {
+            s.param_list().is_some() || (s.self_token().is_some() && path.parent_path().is_none())
+        }) {
             // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
+            // don't try to qualify sole `self` either, they are usually locals, but are returned as modules due to namespace classing
             return None;
         }