codegen, text: remove vestigial Option/Result wraps and redundant clones#123
Draft
iainmcgin wants to merge 1 commit into
Draft
codegen, text: remove vestigial Option/Result wraps and redundant clones#123iainmcgin wants to merge 1 commit into
iainmcgin wants to merge 1 commit into
Conversation
Three classes of `clippy::unnecessary_wraps` and `clippy::redundant_clone` findings (nursery group) in hand-written sources: - `singular_skip_predicate` returned `Option<&'static str>` but every arm was `Some`. It now returns `&'static str` and the caller wraps the one branch where the value is conditional on field shape. A doc comment records the invariant. - `repeated_to_owned` returned `Result<TokenStream, CodeGenError>` but the body was a single infallible `match`. The vestigial `Result` meant the caller's `?` was propagating an error that could never occur, and the signature implied a failure mode it didn't have. It now returns `TokenStream` directly, mirroring the asymmetry between it and the genuinely-fallible `singular_to_owned`. - The tokenizer's `emit` and `emit_eof` helpers returned `Result<Token<'a>, ParseError>` purely so the FSM's `return self.emit(...)` tail calls didn't need an `Ok(...)` wrap. The 12 call sites now wrap explicitly, which makes the success/failure partition of `parse_next` visible at every return: `Ok(self.emit(...))` always succeeds, `Err(self.err_here(...))` always fails, `self.parse_*()` delegates. - Two `bytes_type.clone()` calls in `compute_field_info` sat in mutually-exclusive `if`/`else if` branches alongside a third branch that already moved the value. Both clones were redundant; each execution path moves `bytes_type` at most once. No change to generated output. `task lint`, `task test`, and `task gen-wkt-types` all pass with no drift.
|
All contributors have signed the CLA ✍️ ✅ |
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.
Follow-up to #121: addresses the remaining actionable findings from the code-style audit —
clippy::unnecessary_wraps(4 sites) andclippy::redundant_clone(2 sites), both nursery lints.Changes
buffa-codegen/src/message.rs::singular_skip_predicate— returnedOption<&'static str>but every match arm wasSome(...). Now returns&'static str; the callerskip_serializing_predicatewraps it for the one branch where the value is conditional on field shape (the other branches already produce their ownNone/Some). A doc comment records that singular fields always have a default-value predicate.buffa-codegen/src/view.rs::repeated_to_owned— returnedResult<TokenStream, CodeGenError>but the body was a single infalliblematch. The signature implied a failure mode it didn't have, and the caller's?was propagating an error that could never occur. Now returnsTokenStreamdirectly, which makes the asymmetry between it and the genuinely-fallible siblingsingular_to_ownedhonest.buffa/src/text/token.rs::emit/::emit_eof— returnedResult<Token<'a>, ParseError>purely so the FSM'sreturn self.emit(...)tail calls didn't need anOk(...)wrap. The 12 call sites now wrap explicitly, which makes the success/failure partition ofparse_nextvisible at every return:Ok(self.emit(...))always succeeds,Err(self.err_here(...))always fails,self.parse_*()delegates. Before, the success path'sResulttyping was implicit while the error path's was explicit.buffa-codegen/src/message.rs::compute_field_info— twobytes_type.clone()calls in mutually-exclusiveif/else ifbranches alongside a third branch that already moved the value. Both clones removed; each execution path movesbytes_typeat most once.Notes
No change to generated output —
task gen-wkt-typesproduced no drift.task lintandtask testboth pass. Net 47/-45.