mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 07:03:57 +00:00
v3
This commit is contained in:
parent
68d24b69d4
commit
38491fcf07
1 changed files with 5 additions and 7 deletions
|
@ -116,8 +116,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(call_info, mut_node)| {
|
.map(|(call_info, mut_node)| {
|
||||||
let replacement =
|
let replacement =
|
||||||
inline(&ctx.sema, def_file, function, &func_body, ¶ms, &call_info)
|
inline(&ctx.sema, def_file, function, &func_body, ¶ms, &call_info);
|
||||||
.expect("inline() should return an Expr");
|
|
||||||
ted::replace(mut_node, replacement.syntax());
|
ted::replace(mut_node, replacement.syntax());
|
||||||
})
|
})
|
||||||
.count();
|
.count();
|
||||||
|
@ -219,7 +218,7 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
||||||
}
|
}
|
||||||
|
|
||||||
let syntax = call_info.node.syntax().clone();
|
let syntax = call_info.node.syntax().clone();
|
||||||
let replacement = inline(&ctx.sema, file_id, function, &fn_body, ¶ms, &call_info)?;
|
let replacement = inline(&ctx.sema, file_id, function, &fn_body, ¶ms, &call_info);
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("inline_call", AssistKind::RefactorInline),
|
AssistId("inline_call", AssistKind::RefactorInline),
|
||||||
label,
|
label,
|
||||||
|
@ -305,7 +304,7 @@ fn inline(
|
||||||
fn_body: &ast::BlockExpr,
|
fn_body: &ast::BlockExpr,
|
||||||
params: &[(ast::Pat, Option<ast::Type>, hir::Param)],
|
params: &[(ast::Pat, Option<ast::Type>, hir::Param)],
|
||||||
CallInfo { node, arguments, generic_arg_list }: &CallInfo,
|
CallInfo { node, arguments, generic_arg_list }: &CallInfo,
|
||||||
) -> Option<ast::Expr> {
|
) -> ast::Expr {
|
||||||
let mut body = if sema.hir_file_for(fn_body.syntax()).is_macro() {
|
let mut body = if sema.hir_file_for(fn_body.syntax()).is_macro() {
|
||||||
cov_mark::hit!(inline_call_defined_in_macro);
|
cov_mark::hit!(inline_call_defined_in_macro);
|
||||||
if let Some(body) = ast::BlockExpr::cast(insert_ws_into(fn_body.syntax().clone())) {
|
if let Some(body) = ast::BlockExpr::cast(insert_ws_into(fn_body.syntax().clone())) {
|
||||||
|
@ -376,7 +375,6 @@ fn inline(
|
||||||
ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
|
ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.into_iter()
|
|
||||||
.for_each(|usage| {
|
.for_each(|usage| {
|
||||||
ted::replace(usage, &this());
|
ted::replace(usage, &this());
|
||||||
});
|
});
|
||||||
|
@ -490,7 +488,7 @@ fn inline(
|
||||||
};
|
};
|
||||||
body.reindent_to(original_indentation);
|
body.reindent_to(original_indentation);
|
||||||
|
|
||||||
Some(match body.tail_expr() {
|
match body.tail_expr() {
|
||||||
Some(expr) if !is_async_fn && body.statements().next().is_none() => expr,
|
Some(expr) if !is_async_fn && body.statements().next().is_none() => expr,
|
||||||
_ => match node
|
_ => match node
|
||||||
.syntax()
|
.syntax()
|
||||||
|
@ -503,7 +501,7 @@ fn inline(
|
||||||
}
|
}
|
||||||
_ => ast::Expr::BlockExpr(body),
|
_ => ast::Expr::BlockExpr(body),
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_expr_as_record_field(usage: &PathExpr) -> Option<ast::RecordExprField> {
|
fn path_expr_as_record_field(usage: &PathExpr) -> Option<ast::RecordExprField> {
|
||||||
|
|
Loading…
Reference in a new issue