Skip to content

Commit 6627b47

Browse files
committed
Auto merge of rust-lang#13090 - ice1k:master, r=Veykril
Do not substitute `Self` when in same impl block Fix rust-lang#13076
2 parents b2bf37c + 148bdf8 commit 6627b47

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

crates/ide-assists/src/handlers/inline_call.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,16 @@ fn inline(
311311
} else {
312312
fn_body.clone_for_update()
313313
};
314-
if let Some(t) = body.syntax().ancestors().find_map(ast::Impl::cast).and_then(|i| i.self_ty()) {
315-
body.syntax()
316-
.descendants_with_tokens()
317-
.filter_map(NodeOrToken::into_token)
318-
.filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
319-
.for_each(|tok| ted::replace(tok, t.syntax()));
314+
if let Some(imp) = body.syntax().ancestors().find_map(ast::Impl::cast) {
315+
if !node.syntax().ancestors().any(|anc| &anc == imp.syntax()) {
316+
if let Some(t) = imp.self_ty() {
317+
body.syntax()
318+
.descendants_with_tokens()
319+
.filter_map(NodeOrToken::into_token)
320+
.filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
321+
.for_each(|tok| ted::replace(tok, t.syntax()));
322+
}
323+
}
320324
}
321325
let usages_for_locals = |local| {
322326
Definition::Local(local)
@@ -1221,6 +1225,31 @@ impl A {
12211225
fn main() {
12221226
A(114514);
12231227
}
1228+
"#,
1229+
)
1230+
}
1231+
1232+
#[test]
1233+
fn inline_call_with_self_type_but_within_same_impl() {
1234+
check_assist(
1235+
inline_call,
1236+
r#"
1237+
struct A(u32);
1238+
impl A {
1239+
fn f() -> Self { Self(1919810) }
1240+
fn main() {
1241+
Self::f$0();
1242+
}
1243+
}
1244+
"#,
1245+
r#"
1246+
struct A(u32);
1247+
impl A {
1248+
fn f() -> Self { Self(1919810) }
1249+
fn main() {
1250+
Self(1919810);
1251+
}
1252+
}
12241253
"#,
12251254
)
12261255
}

0 commit comments

Comments
 (0)