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

Code before:
                            );

                            // Emit a diagnostic if ClassVar and Final are combined in a class that is
                            // not a dataclass, since Final already implies the semantics of ClassVar.
                            let classvar_and_final =
                                (matches!(type_qualifier, SpecialFormType::Final)
                                    && type_and_qualifiers
                                        .qualifiers
                                        .contains(TypeQualifiers::CLASS_VAR))
                                    || (matches!(type_qualifier, SpecialFormType::ClassVar)
                                        && type_and_qualifiers
                                            .qualifiers
                                            .contains(TypeQualifiers::FINAL));
                            let inside_non_dataclass_class =
                                nearest_enclosing_class(self.db(), self.index, self.scope())
                                    .is_none_or(|class| !class.is_dataclass_like(self.db()));
                            if classvar_and_final && inside_non_dataclass_class {
                                if let Some(builder) = self
                                    .context
                                    .report_lint(&REDUNDANT_FINAL_CLASSVAR, subscript)
                                {
                                    builder.into_diagnostic(format_args!(
                                        "`Combining `ClassVar` and `Final` is redundant"
                                    ));
                                }
                            }

                            match type_qualifier {
                                SpecialFormType::ClassVar => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::CLASS_VAR);
                                    if type_and_qualifiers
                                        .inner_type()
                                        .has_non_self_typevar(self.db())
                                        && let Some(builder) =
                                            self.context.report_lint(&INVALID_TYPE_FORM, subscript)
                                    {
                                        builder.into_diagnostic(
                                            "`ClassVar` cannot contain type variables",
                                        );
                                    }
                                }
                                SpecialFormType::Final => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::FINAL);
                                }
                                SpecialFormType::Required => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::REQUIRED);
                                }
                                SpecialFormType::NotRequired => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::NOT_REQUIRED);
                                }
                                SpecialFormType::ReadOnly => {

Review comment (suggestion):
```suggestion
                            if classvar_and_final
                            && inside_non_dataclass_class
                            && let Some(builder) = self
                                .context
                                .report_lint(&REDUNDANT_FINAL_CLASSVAR, subscript)
                            {
                                builder.into_diagnostic(format_args!(
                                    "`Combining `ClassVar` and `Final` is redundant"
                                ));
                            }
```

Code after:
                            );

                            // Emit a diagnostic if ClassVar and Final are combined in a class that is
                            // not a dataclass, since Final already implies the semantics of ClassVar.
                            let classvar_and_final = match type_qualifier {
                                SpecialFormType::Final => type_and_qualifiers
                                    .qualifiers
                                    .contains(TypeQualifiers::CLASS_VAR),
                                SpecialFormType::ClassVar => type_and_qualifiers
                                    .qualifiers
                                    .contains(TypeQualifiers::FINAL),
                                _ => false,
                            };
                            if classvar_and_final
                                && nearest_enclosing_class(self.db(), self.index, self.scope())
                                    .is_none_or(|class| !class.is_dataclass_like(self.db()))
                                && let Some(builder) = self
                                    .context
                                    .report_lint(&REDUNDANT_FINAL_CLASSVAR, subscript)
                            {
                                builder.into_diagnostic(format_args!(
                                    "`Combining `ClassVar` and `Final` is redundant"
                                ));
                            }

                            match type_qualifier {
                                SpecialFormType::ClassVar => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::CLASS_VAR);
                                    if type_and_qualifiers
                                        .inner_type()
                                        .has_non_self_typevar(self.db())
                                        && let Some(builder) =
                                            self.context.report_lint(&INVALID_TYPE_FORM, subscript)
                                    {
                                        builder.into_diagnostic(
                                            "`ClassVar` cannot contain type variables",
                                        );
                                    }
                                }
                                SpecialFormType::Final => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::FINAL);
                                }
                                SpecialFormType::Required => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::REQUIRED);
                                }
                                SpecialFormType::NotRequired => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::NOT_REQUIRED);
                                }
                                SpecialFormType::ReadOnly => {
                                    type_and_qualifiers.add_qualifier(TypeQualifiers::READ_ONLY);
                                }