mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-04 01:08:47 +00:00
Auto merge of #13090 - ice1k:master, r=Veykril
Do not substitute `Self` when in same impl block Fix #13076
This commit is contained in:
commit
6627b473e2
1 changed files with 35 additions and 6 deletions
|
@ -311,12 +311,16 @@ fn inline(
|
||||||
} else {
|
} else {
|
||||||
fn_body.clone_for_update()
|
fn_body.clone_for_update()
|
||||||
};
|
};
|
||||||
if let Some(t) = body.syntax().ancestors().find_map(ast::Impl::cast).and_then(|i| i.self_ty()) {
|
if let Some(imp) = body.syntax().ancestors().find_map(ast::Impl::cast) {
|
||||||
body.syntax()
|
if !node.syntax().ancestors().any(|anc| &anc == imp.syntax()) {
|
||||||
.descendants_with_tokens()
|
if let Some(t) = imp.self_ty() {
|
||||||
.filter_map(NodeOrToken::into_token)
|
body.syntax()
|
||||||
.filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
|
.descendants_with_tokens()
|
||||||
.for_each(|tok| ted::replace(tok, t.syntax()));
|
.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| {
|
let usages_for_locals = |local| {
|
||||||
Definition::Local(local)
|
Definition::Local(local)
|
||||||
|
@ -1221,6 +1225,31 @@ impl A {
|
||||||
fn main() {
|
fn main() {
|
||||||
A(114514);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue