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

Code before:
            op: Operator::BitOr,
            left,
            right,
            range: _,
            node_index: _,
        }) => {
            // Analyze the left-hand side of the `|` operator.
            if let Some(never_like) = NeverLike::from_expr(left, checker.semantic()) {
                let mut diagnostic = checker.report_diagnostic(
                    NeverUnion {
                        never_like,
                        union_like: UnionLike::PEP604,
                    },
                    left.range(),
                );
                // Avoid producing code that would raise an exception when
                // `Never | None` would be fixed to `None | None`.
                // Instead do not provide a fix. No action needed for `typing.Union`,
                // as `Union[None, None]` is valid Python.
                // See https://github.com/astral-sh/ruff/issues/14567.
                if !is_pep604_union_with_bare_none(checker.semantic()) {
                    let applicability = if checker.comment_ranges().intersects(expr.range()) {
                        Applicability::Unsafe
                    } else {
                        Applicability::Safe
                    };
                    diagnostic.set_fix(Fix::applicable_edit(
                        Edit::range_replacement(
                            checker.locator().slice(right.as_ref()).to_string(),
                            expr.range(),
                        ),
                        applicability,
                    ));
                }
            }

            // Analyze the right-hand side of the `|` operator.
            if let Some(never_like) = NeverLike::from_expr(right, checker.semantic()) {
                let mut diagnostic = checker.report_diagnostic(
                    NeverUnion {
                        never_like,
                        union_like: UnionLike::PEP604,
                    },
                    right.range(),
                );
                if !is_pep604_union_with_bare_none(checker.semantic()) {
                    let applicability = if checker.comment_ranges().intersects(expr.range()) {
                        Applicability::Unsafe
                    } else {
                        Applicability::Safe
                    };

Review comment (suggestion):
Is `expr` the same in each of these cases? I would be tempted to compute the `applicability` once outside of the `match` and then reuse it in each of these places if so.

Code after:
        Applicability::Safe
    };

    match expr {
        // Ex) `typing.NoReturn | int`
        Expr::BinOp(ExprBinOp {
            op: Operator::BitOr,
            left,
            right,
            range: _,
            node_index: _,
        }) => {
            // Analyze the left-hand side of the `|` operator.
            if let Some(never_like) = NeverLike::from_expr(left, checker.semantic()) {
                let mut diagnostic = checker.report_diagnostic(
                    NeverUnion {
                        never_like,
                        union_like: UnionLike::PEP604,
                    },
                    left.range(),
                );
                // Avoid producing code that would raise an exception when
                // `Never | None` would be fixed to `None | None`.
                // Instead do not provide a fix. No action needed for `typing.Union`,
                // as `Union[None, None]` is valid Python.
                // See https://github.com/astral-sh/ruff/issues/14567.
                if !is_pep604_union_with_bare_none(checker.semantic()) {
                    diagnostic.set_fix(Fix::applicable_edit(
                        Edit::range_replacement(
                            checker.locator().slice(right.as_ref()).to_string(),
                            expr.range(),
                        ),
                        applicability,
                    ));
                }
            }

            // Analyze the right-hand side of the `|` operator.
            if let Some(never_like) = NeverLike::from_expr(right, checker.semantic()) {
                let mut diagnostic = checker.report_diagnostic(
                    NeverUnion {
                        never_like,
                        union_like: UnionLike::PEP604,
                    },
                    right.range(),
                );
                if !is_pep604_union_with_bare_none(checker.semantic()) {
                    diagnostic.set_fix(Fix::applicable_edit(
                        Edit::range_replacement(
                            checker.locator().slice(left.as_ref()).to_string(),
                            expr.range(),