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

Code before:
    /// we only permit classes to inherit from class-literal types,
    /// `Todo`, `Unknown` or `Any`. Anything else results in us
    /// emitting a diagnostic.
    ///
    /// This variant records the indices and types of class bases
    /// that we deem to be invalid. The indices are the indices of nodes
    /// in the bases list of the class's [`StmtClassDef`](ruff_python_ast::StmtClassDef) node.
    /// Each index is the index of a node representing an invalid base.
    InvalidBases(Box<[(usize, Type<'db>)]>),

    /// The class has one or more duplicate bases.
    /// See [`DuplicateBaseError`] for more details.
    DuplicateBases(Box<[DuplicateBaseError<'db>]>),

    /// The class uses PEP-695 parameters and also inherits from `Generic[]`.
    Pep695ClassWithGenericInheritance,

    /// A cycle was encountered resolving the class' bases.
    InheritanceCycle,

    /// The MRO is otherwise unresolvable through the C3-merge algorithm.
    ///
    /// See [`c3_merge`] for more details.
    UnresolvableMro {
        bases_list: Box<[Type<'db>]>,
        generic_fix: Option<usize>,
    },
}

impl<'db> StaticMroErrorKind<'db> {
    pub(super) fn into_mro_error(
        self,
        db: &'db dyn Db,
        class: ClassType<'db>,
    ) -> StaticMroError<'db> {
        StaticMroError {
            kind: self,
            fallback_mro: Mro::from_error(db, class),
        }
    }
}

/// Error recording the fact that a class definition was found to have duplicate bases.
#[derive(Debug, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
pub(super) struct DuplicateBaseError<'db> {
    /// The base that is duplicated in the class's bases list.
    pub(super) duplicate_base: ClassBase<'db>,
    /// The index of the first occurrence of the base in the class's bases list.
    pub(super) first_index: usize,
    /// The indices of the base's later occurrences in the class's bases list.
    pub(super) later_indices: Box<[usize]>,

Review comment (suggestion):
```suggestion
        /// If the error can be resolved by moving a `Generic[]` base
        /// to the end of the MRO, this field will be `Some(i)`,
        /// where `i` is the index of the `Generic[]` base. This allows
        /// us to construct an autofix when the diagnostic is emitted.
        generic_fix: Option<usize>,
```

Code after:
    ///
    /// To avoid excessive complexity in our implementation,
    /// we only permit classes to inherit from class-literal types,
    /// `Todo`, `Unknown` or `Any`. Anything else results in us
    /// emitting a diagnostic.
    ///
    /// This variant records the indices and types of class bases
    /// that we deem to be invalid. The indices are the indices of nodes
    /// in the bases list of the class's [`StmtClassDef`](ruff_python_ast::StmtClassDef) node.
    /// Each index is the index of a node representing an invalid base.
    InvalidBases(Box<[(usize, Type<'db>)]>),

    /// The class has one or more duplicate bases.
    /// See [`DuplicateBaseError`] for more details.
    DuplicateBases(Box<[DuplicateBaseError<'db>]>),

    /// The class uses PEP-695 parameters and also inherits from `Generic[]`.
    Pep695ClassWithGenericInheritance,

    /// A cycle was encountered resolving the class' bases.
    InheritanceCycle,

    /// The MRO is otherwise unresolvable through the C3-merge algorithm.
    ///
    /// See [`c3_merge`] for more details.
    UnresolvableMro {
        bases_list: Box<[Type<'db>]>,
        /// If the error can be resolved by moving a `Generic[]` base
        /// to the end of the MRO, this field indicates the index of
        /// the `Generic[]` base. This allows us to provide an
        /// autofix when the diagnostic is emitted.
        generic_index: Option<usize>,
    },
}

impl<'db> StaticMroErrorKind<'db> {
    pub(super) fn into_mro_error(
        self,
        db: &'db dyn Db,
        class: ClassType<'db>,
    ) -> StaticMroError<'db> {
        StaticMroError {
            kind: self,
            fallback_mro: Mro::from_error(db, class),
        }
    }
}

/// Error recording the fact that a class definition was found to have duplicate bases.
#[derive(Debug, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
pub(super) struct DuplicateBaseError<'db> {