Skip to content

Avoid clippy::unit_arg in generated builder code for unit-typed properties - #1037

Open
danieleades wants to merge 1 commit into
oxidecomputer:mainfrom
danieleades:fix/builder-unit-arg
Open

Avoid clippy::unit_arg in generated builder code for unit-typed properties#1037
danieleades wants to merge 1 commit into
oxidecomputer:mainfrom
danieleades:fix/builder-unit-arg

Conversation

@danieleades

@danieleades danieleades commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Problem

For struct properties whose type is the unit type () (produced by null schemas), builder-mode codegen emits expressions that pass a unit value to Ok(..):

  • in impl Default for builder::T: field: Ok(Default::default())
  • in impl From<super::T> for builder::T: field: Ok(value.field)

Both trip clippy's warn-by-default unit_arg lint. Generating builder-mode output for the typify-impl/tests/github.json fixture produces 105 such warnings. cargo-typify's generated #![allow(..)] prelude doesn't cover unit_arg, and consumers using the macro or build.rs get the warnings in their own builds.

Fix

Detect unit-typed properties in output_struct and emit Ok(()) directly in the builder's Default and From impls. This is semantically identical: reading or defaulting a unit field always yields () and has no effects. For an all-unit struct, the generated conversion names its otherwise-unused source parameter _value.

Testing

  • Added the committed builder-unit-property schema/output pair, which exercises builder mode and shows Ok(()) in both generated implementations.
  • Compiled the github.json builder output with its generated lint-allow prelude removed under cargo clippy --all-targets -- -D clippy::unit_arg; no unit_arg diagnostics remain.
  • cargo test --workspace --locked passes and cargo fmt --all -- --check is clean.

Trade-offs

None behavioral- only the spelling of generated initializers and an unused all-unit conversion parameter changes.

@danieleades
danieleades force-pushed the fix/builder-unit-arg branch from 88f3669 to fa06c1d Compare July 21, 2026 07:37
@danieleades
danieleades force-pushed the fix/builder-unit-arg branch from fa06c1d to c07f7e4 Compare July 28, 2026 08:14
…rties

For struct properties whose type is the unit type () (produced by null
schemas), the generated builder code passed a unit value to Ok(..) in
the builder's Default impl and in the From<T> impl, tripping clippy's
warn-by-default unit_arg lint. Emit Ok(()) directly for such properties
instead; this is semantically identical.
@danieleades
danieleades force-pushed the fix/builder-unit-arg branch from c07f7e4 to 68998ab Compare July 28, 2026 08:28
@danieleades

Copy link
Copy Markdown
Contributor Author

not sure the juice is worth the squeeze on this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant