internal: make::expr_tuple should return ast::TupleExpr

This commit is contained in:
Giga Bowser 2024-12-16 14:27:31 -05:00
parent c549be9ab6
commit f388482119
6 changed files with 9 additions and 8 deletions

View file

@ -1879,7 +1879,7 @@ fn make_body(ctx: &AssistContext<'_>, old_indent: IndentLevel, fun: &Function) -
.iter()
.map(|var| path_expr_from_local(ctx, var.local, fun.mods.edition));
let expr = make::expr_tuple(exprs);
tail_expr = Some(expr);
tail_expr = Some(expr.into());
}
},
};
@ -2130,13 +2130,13 @@ fn make_rewritten_flow(handler: &FlowHandler, arg_expr: Option<ast::Expr>) -> Op
make::arg_list(iter::once(make::expr_unit())),
),
FlowHandler::IfOption { .. } => {
let expr = arg_expr.unwrap_or_else(|| make::expr_tuple(Vec::new()));
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
let args = make::arg_list(iter::once(expr));
make::expr_call(make::expr_path(make::ext::ident_path("Some")), args)
}
FlowHandler::MatchOption { .. } => make::expr_path(make::ext::ident_path("None")),
FlowHandler::MatchResult { .. } => {
let expr = arg_expr.unwrap_or_else(|| make::expr_tuple(Vec::new()));
let expr = arg_expr.unwrap_or_else(|| make::expr_unit());
let args = make::arg_list(iter::once(expr));
make::expr_call(make::expr_path(make::ext::ident_path("Err")), args)
}

View file

@ -152,7 +152,7 @@ fn compute_dbg_replacement(macro_expr: ast::MacroExpr) -> Option<(TextRange, Opt
exprs => {
let exprs = exprs.iter().cloned().map(replace_nested_dbgs);
let expr = make::expr_tuple(exprs);
(macro_call.syntax().text_range(), Some(expr))
(macro_call.syntax().text_range(), Some(expr.into()))
}
})
}

View file

@ -61,7 +61,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
}
}
None => {
let empty_tuple = make::expr_tuple([]);
let empty_tuple = make::expr_unit();
make::let_stmt(pattern, ty, Some(empty_tuple)).to_string()
}
};

View file

@ -541,7 +541,7 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn, trait_ref: Option<TraitRef>) -
arms.push(make::match_arm(Some(lhs), None, rhs));
}
let match_target = make::expr_tuple(vec![lhs_name, rhs_name]);
let match_target = make::expr_tuple([lhs_name, rhs_name]).into();
let list = make::match_arm_list(arms).indent(ast::edit::IndentLevel(1));
make::expr_match(match_target, list)
}

View file

@ -656,7 +656,7 @@ pub fn expr_field(receiver: ast::Expr, field: &str) -> ast::Expr {
pub fn expr_paren(expr: ast::Expr) -> ast::Expr {
expr_from_text(&format!("({expr})"))
}
pub fn expr_tuple(elements: impl IntoIterator<Item = ast::Expr>) -> ast::Expr {
pub fn expr_tuple(elements: impl IntoIterator<Item = ast::Expr>) -> ast::TupleExpr {
let expr = elements.into_iter().format(", ");
expr_from_text(&format!("({expr})"))
}

View file

@ -344,7 +344,8 @@ mod tests {
make::expr_literal("2").into(),
),
make::expr_literal("true").into(),
]),
])
.into(),
);
let to_wrap = root.syntax().descendants().find_map(ast::TupleExpr::cast).unwrap();