Skip to content

Commit

Permalink
Auto merge of rust-lang#13090 - ice1k:master, r=Veykril
Browse files Browse the repository at this point in the history
Do not substitute `Self` when in same impl block

Fix rust-lang#13076
  • Loading branch information
bors committed Aug 23, 2022
2 parents b2bf37c + 148bdf8 commit 6627b47
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions crates/ide-assists/src/handlers/inline_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,16 @@ fn inline(
} else {
fn_body.clone_for_update()
};
if let Some(t) = body.syntax().ancestors().find_map(ast::Impl::cast).and_then(|i| i.self_ty()) {
body.syntax()
.descendants_with_tokens()
.filter_map(NodeOrToken::into_token)
.filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
.for_each(|tok| ted::replace(tok, t.syntax()));
if let Some(imp) = body.syntax().ancestors().find_map(ast::Impl::cast) {
if !node.syntax().ancestors().any(|anc| &anc == imp.syntax()) {
if let Some(t) = imp.self_ty() {
body.syntax()
.descendants_with_tokens()
.filter_map(NodeOrToken::into_token)
.filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
.for_each(|tok| ted::replace(tok, t.syntax()));
}
}
}
let usages_for_locals = |local| {
Definition::Local(local)
Expand Down Expand Up @@ -1221,6 +1225,31 @@ impl A {
fn main() {
A(114514);
}
"#,
)
}

#[test]
fn inline_call_with_self_type_but_within_same_impl() {
check_assist(
inline_call,
r#"
struct A(u32);
impl A {
fn f() -> Self { Self(1919810) }
fn main() {
Self::f$0();
}
}
"#,
r#"
struct A(u32);
impl A {
fn f() -> Self { Self(1919810) }
fn main() {
Self(1919810);
}
}
"#,
)
}
Expand Down

0 comments on commit 6627b47

Please sign in to comment.