Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/constraints.rs (Rust)

Code before:
                    }
                    (Type::TypeVar(bound_typevar), _) => {
                        ConstrainedTypeVar::new(db, bound_typevar, Type::Never, right_upper)
                    }
                    (_, Type::TypeVar(bound_typevar)) => {
                        ConstrainedTypeVar::new(db, bound_typevar, right_lower, Type::object())
                    }
                    _ => return,
                };
                self.add_pair_implication(db, left_constraint, right_constraint, post_constraint);
                self.enqueue_constraint(post_constraint);
            };

        try_one_direction(left_constraint, right_constraint);
        try_one_direction(right_constraint, left_constraint);
    }

    fn add_concrete_sequents(
        &mut self,
        db: &'db dyn Db,
        left_constraint: ConstrainedTypeVar<'db>,
        right_constraint: ConstrainedTypeVar<'db>,
    ) {
        // These might seem redundant with the intersection check below, since `a → b` means that
        // `a ∧ b = a`. But we are not normalizing constraint bounds, and these clauses help us
        // identity constraints that are identical besides e.g. ordering of union/intersection
        // elements. (For instance, these clauses would find `T ≤ τ₁ ∩ τ₂` and `T ≤ τ₂ ∩ τ₁`, and
        // add sequents for `(T ≤ τ₁ ∩ τ₂) → (T ≤ τ₂ ∩ τ₁)` and vice versa.)
        if left_constraint.implies(db, right_constraint) {
            self.add_single_implication(left_constraint, right_constraint);
        }
        if right_constraint.implies(db, left_constraint) {
            self.add_single_implication(right_constraint, left_constraint);
        }

        match left_constraint.intersect(db, right_constraint) {
            Some(intersection_constraint) => {
                self.add_pair_implication(
                    db,
                    left_constraint,
                    right_constraint,
                    intersection_constraint,
                );
                self.add_single_implication(intersection_constraint, left_constraint);
                self.add_single_implication(intersection_constraint, right_constraint);
                self.enqueue_constraint(intersection_constraint);
            }
            None => {
                self.add_impossibility(db, left_constraint, right_constraint);
            }
        }

Review comment (suggestion):
```suggestion
        // identify constraints that are identical besides e.g. ordering of union/intersection
```

Code after:
                        if bound_typevar.is_same_typevar_as(db, other_bound_typevar) =>
                    {
                        ConstrainedTypeVar::new(db, bound_typevar, right_lower, right_upper)
                    }
                    (Type::TypeVar(bound_typevar), _) => {
                        ConstrainedTypeVar::new(db, bound_typevar, Type::Never, right_upper)
                    }
                    (_, Type::TypeVar(bound_typevar)) => {
                        ConstrainedTypeVar::new(db, bound_typevar, right_lower, Type::object())
                    }
                    _ => return,
                };
                self.add_pair_implication(db, left_constraint, right_constraint, post_constraint);
                self.enqueue_constraint(post_constraint);
            };

        try_one_direction(left_constraint, right_constraint);
        try_one_direction(right_constraint, left_constraint);
    }

    fn add_concrete_sequents(
        &mut self,
        db: &'db dyn Db,
        left_constraint: ConstrainedTypeVar<'db>,
        right_constraint: ConstrainedTypeVar<'db>,
    ) {
        // These might seem redundant with the intersection check below, since `a → b` means that
        // `a ∧ b = a`. But we are not normalizing constraint bounds, and these clauses help us
        // identify constraints that are identical besides e.g. ordering of union/intersection
        // elements. (For instance, when processing `T ≤ τ₁ & τ₂` and `T ≤ τ₂ & τ₁`, these clauses
        // would add sequents for `(T ≤ τ₁ & τ₂) → (T ≤ τ₂ & τ₁)` and vice versa.)
        if left_constraint.implies(db, right_constraint) {
            self.add_single_implication(left_constraint, right_constraint);
        }
        if right_constraint.implies(db, left_constraint) {
            self.add_single_implication(right_constraint, left_constraint);
        }

        match left_constraint.intersect(db, right_constraint) {
            Some(intersection_constraint) => {
                self.add_pair_implication(
                    db,
                    left_constraint,
                    right_constraint,
                    intersection_constraint,
                );
                self.add_single_implication(intersection_constraint, left_constraint);
                self.add_single_implication(intersection_constraint, right_constraint);
                self.enqueue_constraint(intersection_constraint);
            }
            None => {