Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview
Regression tests cover a struct with a Reviewed by Cursor Bugbot for commit b478b78. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 22 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

Summary
Fix variable name shadowing in
#[derive(Hash)]and#[derive(Serde)]code generation when a struct field is namedvalue(forHash) orserialized(forSerde).The generated
update_stateimplementation forHashused to bind each member into a local variable named after the field itself (e.g.,let value = ...). If a field was namedvalue, this shadowed theupdate_statefunction parametervalue, causing incorrect code generation. Similarly, theSerdedeserializeimplementation bound members into locals named after the field, which could shadow theref serializedparameter if a field was namedserialized.The fix prefixes all generated intermediate locals with
__hash_derive_member_(forHash) and__serde_member_(forSerde) to avoid any collision with parameter names or other identifiers.Type of change
Please check one:
Why is this change needed?
A struct with a field named
valuewould cause the#[derive(Hash)]macro to emit code where the local variablelet value = ...shadowed thevalueparameter ofupdate_state, producing broken generated code. Likewise, a field namedserializedin a#[derive(Serde)]struct would shadow theref serializedparameter in the generateddeserializefunction.What was the behavior or documentation before?
Generated
Hash::update_statecode usedlet {field_name} = ...and then referenced{field_name}.value, which broke whenfield_namewasvalue. GeneratedSerde::deserializecode usedlet {field_name} = ..., which broke whenfield_namewasserialized.What is the behavior or documentation after?
Generated locals are now named
__hash_derive_member_{field_name}and__serde_member_{field_name}respectively, preventing any shadowing of reserved parameter names regardless of what the struct fields are called. Tests coveringStructWithValueFieldForHashandStructWithSerializedFieldare added to confirm correct round-trip behavior.Related issue or discussion (if any)
#10115 #10116
Additional context
All existing snapshot test data files have been updated to reflect the new generated variable names.