diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 5b368c2b40d..2eb7089b7c3 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -373,7 +373,9 @@ fn inline( // 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 // `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 let Some(t) = imp.self_ty() { while let Some(self_tok) = body @@ -1559,6 +1561,64 @@ fn a() -> bool { this == &Enum::A || this == &Enum::B } } +"#, + ) + } + + #[test] + fn inline_call_with_self_type_in_macros() { + check_assist( + inline_call, + r#" +trait Trait { + 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 = >::$0f(a); +} +"#, + r#" +trait Trait { + 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 + }; +} "#, ) }