mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 21:05:13 +00:00
fix: self type replacement with macros
This commit is contained in:
parent
3449222ab1
commit
38b5dcb53c
1 changed files with 61 additions and 1 deletions
|
@ -373,7 +373,9 @@ fn inline(
|
||||||
// We should place the following code after last usage of `usages_for_locals`
|
// We should place the following code after last usage of `usages_for_locals`
|
||||||
// because `ted::replace` will change the offset in syntax tree, which makes
|
// because `ted::replace` will change the offset in syntax tree, which makes
|
||||||
// `FileReference` incorrect
|
// `FileReference` incorrect
|
||||||
if let Some(imp) = body.syntax().ancestors().find_map(ast::Impl::cast) {
|
if let Some(imp) =
|
||||||
|
sema.ancestors_with_macros(fn_body.syntax().clone()).find_map(ast::Impl::cast)
|
||||||
|
{
|
||||||
if !node.syntax().ancestors().any(|anc| &anc == imp.syntax()) {
|
if !node.syntax().ancestors().any(|anc| &anc == imp.syntax()) {
|
||||||
if let Some(t) = imp.self_ty() {
|
if let Some(t) = imp.self_ty() {
|
||||||
while let Some(self_tok) = body
|
while let Some(self_tok) = body
|
||||||
|
@ -1559,6 +1561,64 @@ fn a() -> bool {
|
||||||
this == &Enum::A || this == &Enum::B
|
this == &Enum::A || this == &Enum::B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inline_call_with_self_type_in_macros() {
|
||||||
|
check_assist(
|
||||||
|
inline_call,
|
||||||
|
r#"
|
||||||
|
trait Trait<T1> {
|
||||||
|
fn f(a: T1) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_from {
|
||||||
|
($t: ty) => {
|
||||||
|
impl Trait<$t> for $t {
|
||||||
|
fn f(a: $t) -> Self {
|
||||||
|
a as Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
impl_from!(A);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a: A = A{};
|
||||||
|
let b = <A as Trait<A>>::$0f(a);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
trait Trait<T1> {
|
||||||
|
fn f(a: T1) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_from {
|
||||||
|
($t: ty) => {
|
||||||
|
impl Trait<$t> for $t {
|
||||||
|
fn f(a: $t) -> Self {
|
||||||
|
a as Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
impl_from!(A);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a: A = A{};
|
||||||
|
let b = {
|
||||||
|
let a = a;
|
||||||
|
a as A
|
||||||
|
};
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue