Repository navigation
[AUTOMATED] Print a byte converted to bool as a comparison and Boolean constants as false/true in Rust output - #1967
Merged
Merged
Conversation
…parison [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
… test, spec [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…consumer [AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
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.
With
--language rust, a function returningboolcan print a call's byte result ascall() as booland its constant returns as integer literals. Neither compiles: Rust has no integer-to-boolcast, and0is not abool.rustc:
error[E0308]: mismatched types(thereturn 0) anderror[E0054]: cannot cast u64 as bool. With this change:voidone, now uses the callee's recovered return type. Aboolresult keeps the cast, which is valid. A one-byte integer printscall() != 0. Any other result printscall() as u8 != 0, which tests the low byte the caller reads, whatever the callee's printed return type.!=uses Rust's own operator token, so(f() != 0) != ggets parentheses instead of the chainedf() != 0 != g, which does not parse. Elsewhere the existing parentheses are kept.boolprints asfalse/true(as Go output already does) when what consumes it is also Boolean: the return of a function that returnsbool, a declaredboolvariable, or the other side of==/!=.C and Go output do not change. Dumping the datatest and stage corpora before and after, the only differences are two Rust lines in
kuna-outlang-rust(v1 = 0;becomesv1 = false;). In Rust output of 40 decbench binaries, one per project, 3,544 of 3,549 integer literals given to aboolvariable or return now print asfalse/true. An integeras boolis rarer: none in those 40 binaries, and two functions among sshd, bash,ls(-O2 and -O0) and a Cortex-M firmware,sub_b9df0(a0) as bool != (...)andsub_15168(p) as bool. They now print(sub_b9df0(a0) != 0) != (...)andsub_15168(p) != 0. Casts of values that are already Boolean do not change.Tests:
kuna-cli/tests/rust_boolean_conversions.rsgains a case that compiles the emittednarrow_boolwith rustc next to a referencewide_valueand checks it on 16 inputs. Before this change the emitted function does not compile.Model:
anthropic/claude-opus-5-5🤖 Generated with Claude Code
https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU