This commit is contained in:
Ali Bektas 2023-08-15 23:59:29 +02:00
parent 35e0d800f0
commit 6f7460484a

View file

@ -1726,8 +1726,9 @@ fn make_body(
let block = match &fun.body {
FunctionBody::Expr(expr) => {
let expr = rewrite_body_segment(ctx, &fun.params, &handler, expr.syntax())?;
let expr = ast::Expr::cast(expr)?;
let expr = rewrite_body_segment(ctx, &fun.params, &handler, expr.syntax())
.expect("rewrite_body_segment failed.");
let expr = ast::Expr::cast(expr).expect("error while casting body segment to an expr.");
match expr {
ast::Expr::BlockExpr(block) => {
// If the extracted expression is itself a block, there is no need to wrap it inside another block.
@ -1934,27 +1935,24 @@ fn fix_param_usages(
for (param, usages) in usages_for_param {
for usage in usages {
match usage.syntax().ancestors().skip(1).find_map(ast::Expr::cast) {
Some(ast::Expr::MethodCallExpr(_) | ast::Expr::FieldExpr(_)) => {
// do nothing
let expr = usage.syntax().ancestors().skip(1).find_map(ast::Expr::cast);
if let Some(ast::Expr::MethodCallExpr(_) | ast::Expr::FieldExpr(_)) = expr {
continue;
}
Some(ast::Expr::RefExpr(node))
if param.kind() == ParamKind::MutRef && node.mut_token().is_some() =>
if let Some(ast::Expr::RefExpr(node)) = expr {
if (param.kind() == ParamKind::MutRef && node.mut_token().is_some())
|| (param.kind() == ParamKind::SharedRef && node.mut_token().is_none())
{
ted::replace(node.syntax(), node.expr()?.syntax());
continue;
}
Some(ast::Expr::RefExpr(node))
if param.kind() == ParamKind::SharedRef && node.mut_token().is_none() =>
{
ted::replace(node.syntax(), node.expr()?.syntax());
}
Some(_) | None => {
let p = &make::expr_prefix(T![*], usage.clone()).clone_for_update();
ted::replace(usage.syntax(), p.syntax())
}
}
}
}
Some(res)
}