Repository: astral-sh/ruff
File: crates/ruff_linter/src/rules/refurb/rules/fstring_number_format.rs (Rust)

Code before:
    if matches!(
        arg,
        Expr::NumberLiteral(ast::ExprNumberLiteral {
            value: Number::Float(_) | Number::Complex { .. },
            ..
        })
    ) {
        return;
    }

    let maybe_number = if let Some(maybe_number) = arg
        .as_unary_op_expr()
        .filter(|unary_expr| unary_expr.op == UnaryOp::UAdd)
        .map(|unary_expr| &unary_expr.operand)
    {
        maybe_number
    } else {
        arg
    };

    let applicability = if matches!(maybe_number, Expr::NumberLiteral(_))
        && !checker.comment_ranges().intersects(subscript.range())
    {
        Applicability::Safe
    } else if matches!(maybe_number, Expr::NumberLiteral(_)) {
        Applicability::Unsafe
    } else {
        Applicability::DisplayOnly
    };

    let replacement = try_create_replacement(checker, arg, base);

    let mut diagnostic = checker.report_diagnostic(
        FStringNumberFormat {
            replacement: replacement.as_deref().map(SourceCodeSnippet::from_str),
            base,
        },
        subscript.range(),
    );

    if let Some(replacement) = replacement {
        let edit = Edit::range_replacement(replacement, subscript.range());
        diagnostic.set_fix(Fix::applicable_edit(edit, applicability));
    }
}

/// Generate a replacement, if possible.
fn try_create_replacement(checker: &Checker, arg: &Expr, base: Base) -> Option<String> {
    if !matches!(
        arg,
        Expr::NumberLiteral(_) | Expr::Name(_) | Expr::Attribute(_) | Expr::UnaryOp(_)

Review comment (suggestion):
nit: I would probably just nest the check here instead of repeating the `matches!`:


```suggestion
    let applicability = if matches!(maybe_number, Expr::NumberLiteral(_)) {
        if checker.comment_ranges().intersects(subscript.range()) {
			Applicability::Unsafe
		} else {
			Applicability::Safe
		}
```

Code after:
        arg,
        Expr::NumberLiteral(ast::ExprNumberLiteral {
            value: Number::Float(_) | Number::Complex { .. },
            ..
        })
    ) {
        return;
    }

    let maybe_number = if let Some(maybe_number) = arg
        .as_unary_op_expr()
        .filter(|unary_expr| unary_expr.op == UnaryOp::UAdd)
        .map(|unary_expr| &unary_expr.operand)
    {
        maybe_number
    } else {
        arg
    };

    let applicability = if matches!(maybe_number, Expr::NumberLiteral(_)) {
        if checker.comment_ranges().intersects(subscript.range()) {
            Applicability::Unsafe
        } else {
            Applicability::Safe
        }
    } else {
        Applicability::DisplayOnly
    };

    let replacement = try_create_replacement(checker, arg, base);

    let mut diagnostic = checker.report_diagnostic(
        FStringNumberFormat {
            replacement: replacement.as_deref().map(SourceCodeSnippet::from_str),
            base,
        },
        subscript.range(),
    );

    if let Some(replacement) = replacement {
        let edit = Edit::range_replacement(replacement, subscript.range());
        diagnostic.set_fix(Fix::applicable_edit(edit, applicability));
    }
}

/// Generate a replacement, if possible.
fn try_create_replacement(checker: &Checker, arg: &Expr, base: Base) -> Option<String> {
    if !matches!(
        arg,
        Expr::NumberLiteral(_) | Expr::Name(_) | Expr::Attribute(_) | Expr::UnaryOp(_)
    ) {