From 456f5c6d09fa457be9c49aa1f33e532f5051460c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 27 Jul 2021 19:29:47 +0200 Subject: [PATCH] Don't qualify self as crate in add_missing_impl_members assist --- .../src/handlers/add_missing_impl_members.rs | 35 +++++++++++++++++++ crates/ide_db/src/path_transform.rs | 5 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/ide_assists/src/handlers/add_missing_impl_members.rs b/crates/ide_assists/src/handlers/add_missing_impl_members.rs index 8225ae22c6..59d5f48301 100644 --- a/crates/ide_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ide_assists/src/handlers/add_missing_impl_members.rs @@ -812,4 +812,39 @@ impl Foo for () { "#, ) } + + #[test] + fn does_not_requalify_self_as_crate() { + check_assist( + add_missing_default_members, + r" +struct Wrapper(T); + +trait T { + fn f(self) -> Wrapper { + Wrapper(self) + } +} + +impl T for () { + $0 +} +", + r" +struct Wrapper(T); + +trait T { + fn f(self) -> Wrapper { + Wrapper(self) + } +} + +impl T for () { + $0fn f(self) -> Wrapper { + Wrapper(self) + } +} +", + ); + } } diff --git a/crates/ide_db/src/path_transform.rs b/crates/ide_db/src/path_transform.rs index f3d7aa920c..32eb98714b 100644 --- a/crates/ide_db/src/path_transform.rs +++ b/crates/ide_db/src/path_transform.rs @@ -101,8 +101,11 @@ impl<'a> Ctx<'a> { 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; }