Skip to content

Commit 9650578

Browse files
committed
Auto merge of rust-lang#16678 - roife:fix-issue-16660, r=lnicola
fix: panic when inlining callsites inside macros' parameters Close rust-lang#16660, rust-lang#12429, rust-lang#10695. When `inline_into_callers` encounters callsites in macros parameters, it can lead to panics. Since there is no perfect way to handle macros, this PR directly filters out these cases.
2 parents f7f63cc + 61b576c commit 9650578

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

crates/ide-assists/src/handlers/inline_call.rs

+25
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
107107
let call_infos: Vec<_> = name_refs
108108
.into_iter()
109109
.filter_map(CallInfo::from_name_ref)
110+
// FIXME: do not handle callsites in macros' parameters, because
111+
// directly inlining into macros may cause errors.
112+
.filter(|call_info| !ctx.sema.hir_file_for(call_info.node.syntax()).is_macro())
110113
.map(|call_info| {
111114
let mut_node = builder.make_syntax_mut(call_info.node.syntax().clone());
112115
(call_info, mut_node)
@@ -1795,4 +1798,26 @@ fn _hash2(self_: &u64, state: &mut u64) {
17951798
"#,
17961799
)
17971800
}
1801+
1802+
#[test]
1803+
fn inline_into_callers_in_macros_not_applicable() {
1804+
check_assist_not_applicable(
1805+
inline_into_callers,
1806+
r#"
1807+
fn foo() -> u32 {
1808+
42
1809+
}
1810+
1811+
macro_rules! bar {
1812+
($x:expr) => {
1813+
$x
1814+
};
1815+
}
1816+
1817+
fn f() {
1818+
bar!(foo$0());
1819+
}
1820+
"#,
1821+
);
1822+
}
17981823
}

0 commit comments

Comments
 (0)