mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
fix tests
This commit is contained in:
parent
5b56d7bd90
commit
3dd2f99c49
6 changed files with 117 additions and 6 deletions
|
@ -722,8 +722,8 @@ impl ArithKind {
|
|||
fn assist_id(&self) -> AssistId {
|
||||
let s = match self {
|
||||
ArithKind::Saturating => "replace_arith_with_saturating",
|
||||
ArithKind::Checked => "replace_arith_with_saturating",
|
||||
ArithKind::Wrapping => "replace_arith_with_saturating",
|
||||
ArithKind::Checked => "replace_arith_with_checked",
|
||||
ArithKind::Wrapping => "replace_arith_with_wrapping",
|
||||
};
|
||||
|
||||
AssistId(s, AssistKind::RefactorRewrite)
|
||||
|
@ -771,6 +771,10 @@ pub(crate) fn replace_arith(
|
|||
) -> Option<()> {
|
||||
let (lhs, op, rhs) = parse_binary_op(ctx)?;
|
||||
|
||||
if !is_primitive_int(ctx, &lhs) || !is_primitive_int(ctx, &rhs) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let start = lhs.syntax().text_range().start();
|
||||
let end = rhs.syntax().text_range().end();
|
||||
let range = TextRange::new(start, end);
|
||||
|
@ -782,6 +786,13 @@ pub(crate) fn replace_arith(
|
|||
})
|
||||
}
|
||||
|
||||
fn is_primitive_int(ctx: &AssistContext<'_>, expr: &Expr) -> bool {
|
||||
match ctx.sema.type_of_expr(expr) {
|
||||
Some(ty) => ty.adjusted().is_int_or_uint(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the operands of an arithmetic expression (e.g. `1 + 2` or `1.checked_add(2)`)
|
||||
fn parse_binary_op(ctx: &AssistContext<'_>) -> Option<(Expr, ArithOp, Expr)> {
|
||||
let expr = ctx.find_node_at_offset::<BinExpr>()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue