Skip to content

Fix nightly clippy collapsible_match errors in codegen#518

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ci-failure
Closed

Fix nightly clippy collapsible_match errors in codegen#518
Copilot wants to merge 3 commits intomainfrom
copilot/fix-ci-failure

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

Nightly Rust clippy now enforces collapsible_match, causing 4 compile errors in codegen/src/v1/dto.rs that break CI.

Changes

Each fix keeps one match arm per rust::Type. The 4 sites in dto.rs are addressed as follows:

  • Struct in can_derive_serde: Inverted the condition so the "pass" case is in the if-body and the early exit is in else:

    rust::Type::Struct(s) => {
        if can_derive_serde(s, rust_types) {
            // pass
        } else {
            return false;
        }
    }
  • Provided in can_derive_default: Eliminated the nested if entirely with a single-expression return:

    rust::Type::Provided(ty) => {
        // CachedTags has a trivial Default; other Provided types fall through
        // to the field.default_value check below
        return ty.name == "CachedTags" || field.default_value.as_ref().is_some_and(is_rust_default);
    }
  • Alias in ignore_empty_strings: Applied De Morgan's law to invert the compound condition, placing "pass" in the if-body and the action in else (the compound || avoids triggering clippy::if_not_else):

    rust::Type::Alias(field_ty) => {
        if !field.option_type || field_ty.type_ != "String" {
            // pass
        } else {
            g!("if self.{}.as_deref() == Some(\"\") {{", field.name);
            // ...
        }
    }
  • StrEnum in ignore_empty_strings: The simple boolean condition field.option_type cannot be inverted without triggering clippy::if_not_else. Added #[allow(clippy::collapsible_match)] to the containing codegen_dto_ext function as a targeted workaround.

Semantics are unchanged across all 4 sites.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…rors

Co-authored-by: Nugine <30099658+Nugine@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix continuous integration failure Fix nightly clippy collapsible_match errors in codegen Feb 26, 2026
@Nugine Nugine marked this pull request as ready for review February 26, 2026 04:54
Copilot AI review requested due to automatic review settings February 26, 2026 04:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Rust code generator to satisfy newer nightly Clippy collapsible_match linting by rewriting nested if checks inside match arms as match guards, keeping the generated behavior the same while unblocking CI.

Changes:

  • Refactor can_derive_serde to use guarded match arms for recursive Struct checks.
  • Refactor can_derive_default to use a guarded match arm for the CachedTags special-case.
  • Refactor DtoExt::ignore_empty_strings codegen to use guarded match arms for Alias(String) and optional StrEnum handling.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Nugine Nugine added the needs-human-intervention AI PRs that need non-trivial work to make progress label Feb 26, 2026
@Nugine
Copy link
Member

Nugine commented Feb 26, 2026

@copilot Work around the lint by

else {
// pass
}

Keep each match arm corresponding to a rust::Type.

…per rust::Type

Co-authored-by: Nugine <30099658+Nugine@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 26, 2026

@copilot Work around the lint by

else {

...

Done in 399e232. The else { // pass } approach unfortunately doesn't work: nightly clippy treats comment-only else bodies as empty and still fires collapsible_match, and redundant_else fires when the if-body is an early exit.

Each case keeps one arm per rust::Type, fixed as follows:

  • Struct (can_derive_serde): inverted condition — if can_derive_serde { // pass } else { return false; }
  • Provided (can_derive_default): eliminated the if entirely — return ty.name == "CachedTags" || field.default_value...
  • Alias (ignore_empty_strings): De Morgan's inversion — if !field.option_type || field_ty.type_ != "String" { // pass } else { g!()... } (compound || avoids if_not_else)
  • StrEnum (ignore_empty_strings): #[allow(clippy::collapsible_match)] on codegen_dto_ext — simple boolean can't be inverted without triggering if_not_else

@Nugine Nugine closed this Feb 26, 2026
@Nugine Nugine deleted the copilot/fix-ci-failure branch February 26, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-human-intervention AI PRs that need non-trivial work to make progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants