From 36298c622e93f562c8f6c0143730d4becb64d751 Mon Sep 17 00:00:00 2001 From: roife Date: Mon, 26 Feb 2024 20:23:36 +0800 Subject: [PATCH 1/3] fix:do not handle callsites in macros' parameters --- crates/ide-assists/src/handlers/inline_call.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 11b22b6520..fd042edb12 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -107,6 +107,9 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) -> let call_infos: Vec<_> = name_refs .into_iter() .filter_map(CallInfo::from_name_ref) + // FIXME: do not handle callsites in macros' parameters, because + // directly inlining into macros may cause errors. + .filter(|call_info| !ctx.sema.hir_file_for(call_info.node.syntax()).is_macro()) .map(|call_info| { let mut_node = builder.make_syntax_mut(call_info.node.syntax().clone()); (call_info, mut_node) From 38a50cf1a4c0276ce0a4fc8341c8ac23d9e8fd16 Mon Sep 17 00:00:00 2001 From: roife Date: Mon, 26 Feb 2024 20:24:44 +0800 Subject: [PATCH 2/3] test: callsites inside inline_into_callers --- .../ide-assists/src/handlers/inline_call.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index fd042edb12..4095719d9f 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -1798,4 +1798,25 @@ fn _hash2(self_: &u64, state: &mut u64) { "#, ) } + + #[test] + fn inline_into_callers_in_macros_not_applicable() { + check_assist_not_applicable( + inline_into_callers, + r#" +fn foo() -> u32 { + 42 +} + +macro_rules! bar { + ($x:expr) => { + $x + }; +} + +fn f() { + bar!(foo$0()); +} +"#); + } } From 61b576c5ab7464c07a4ef6aa9c8a029ddfe5cf18 Mon Sep 17 00:00:00 2001 From: roife Date: Mon, 26 Feb 2024 22:36:47 +0800 Subject: [PATCH 3/3] fix: fmt --- crates/ide-assists/src/handlers/inline_call.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 4095719d9f..2b9ed86e41 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -1817,6 +1817,7 @@ macro_rules! bar { fn f() { bar!(foo$0()); } -"#); +"#, + ); } }