Avoid clippy::unit_arg in generated builder code for unit-typed properties#1037
Open
danieleades wants to merge 1 commit into
Open
Avoid clippy::unit_arg in generated builder code for unit-typed properties#1037danieleades wants to merge 1 commit into
danieleades wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
For struct properties whose type is the unit type
()(produced by null schemas), builder-mode codegen emits expressions that pass a unit value toOk(..):impl Default for builder::T:field: Ok(Default::default())impl From<super::T> for builder::T:field: Ok(value.field)Both trip clippy's warn-by-default
unit_arglint. Generating builder-mode output for thetypify-impl/tests/github.jsonfixture produces 105 such warnings. cargo-typify's generated#![allow(..)]prelude doesn't coverunit_arg, and consumers using the macro or build.rs get the warnings in their own builds.Fix
Detect unit-typed properties in
output_structand emitOk(())directly in the builder'sDefaultandFromimpls. This is semantically identical: reading or defaulting a unit field always yields()and has no effects.Verified by compiling the github.json builder output (with the
#![allow(..)]prelude stripped) undercargo clippy:unit_argwarnings drop from 105 to 0. No existing golden files change, since none of them exercise a unit-typed property in builder mode.Trade-offs
None behavioral; only the spelling of the generated initializers for unit-typed fields changes.