Skip to content

Commit 6a2a0b7

Browse files
bors[bot]Veykril
andauthored
Merge #9710
9710: fix: Don't qualify self as crate in add_missing_impl_members assist r=Veykril a=Veykril Fixes #7499 Co-authored-by: Lukas Wirth <[email protected]>
2 parents 2c638a4 + 456f5c6 commit 6a2a0b7

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

crates/ide_assists/src/handlers/add_missing_impl_members.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,4 +812,39 @@ impl Foo for () {
812812
"#,
813813
)
814814
}
815+
816+
#[test]
817+
fn does_not_requalify_self_as_crate() {
818+
check_assist(
819+
add_missing_default_members,
820+
r"
821+
struct Wrapper<T>(T);
822+
823+
trait T {
824+
fn f(self) -> Wrapper<Self> {
825+
Wrapper(self)
826+
}
827+
}
828+
829+
impl T for () {
830+
$0
831+
}
832+
",
833+
r"
834+
struct Wrapper<T>(T);
835+
836+
trait T {
837+
fn f(self) -> Wrapper<Self> {
838+
Wrapper(self)
839+
}
840+
}
841+
842+
impl T for () {
843+
$0fn f(self) -> Wrapper<Self> {
844+
Wrapper(self)
845+
}
846+
}
847+
",
848+
);
849+
}
815850
}

crates/ide_db/src/path_transform.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,11 @@ impl<'a> Ctx<'a> {
101101
if path.qualifier().is_some() {
102102
return None;
103103
}
104-
if path.segment().and_then(|s| s.param_list()).is_some() {
104+
if path.segment().map_or(false, |s| {
105+
s.param_list().is_some() || (s.self_token().is_some() && path.parent_path().is_none())
106+
}) {
105107
// don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
108+
// don't try to qualify sole `self` either, they are usually locals, but are returned as modules due to namespace classing
106109
return None;
107110
}
108111

0 commit comments

Comments
 (0)