mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Auto merge of #16678 - roife:fix-issue-16660, r=lnicola
fix: panic when inlining callsites inside macros' parameters Close #16660, #12429, #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.
This commit is contained in:
commit
96505787b4
1 changed files with 25 additions and 0 deletions
|
@ -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)
|
||||
|
@ -1795,4 +1798,26 @@ 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());
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue