[Rust] Do not escape bit set choice names used in accessors - #1121
Open
s1amese2003 wants to merge 1 commit into
Open
[Rust] Do not escape bit set choice names used in accessors#1121s1amese2003 wants to merge 1 commit into
s1amese2003 wants to merge 1 commit into
Conversation
A choice named after a Rust keyword generated accessors such as get_r#type and set_r#type, which do not parse: the raw identifier escaping ends up in the middle of the accessor name and rustc reports "error: prefix `get_r` is unknown". The generated Debug implementation called the same names, and printed the escaping in its labels. A choice is only ever reached through a get_ or set_ prefixed accessor, so the prefixed name is a plain identifier and can never shadow a keyword. The choice name therefore does not need escaping, and escaping it is what breaks the result. C++ generates type() and Go generates Type... for the same schema, so Rust was the only language mangling these names. Resolves aeron-io#1118
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.
Fixes #1118.
What
A set choice named after a Rust keyword generates accessors that do not parse:
The generated
Debugimplementation calls the same names, and prints theescaping in its labels.
Why
generateSingleBitSetformats the choice name withformatFunctionName, whichescapes a name that shadows a Rust keyword as a raw identifier. A choice is only
ever reached through a
get_orset_prefixed accessor, so the prefixed nameis already a plain identifier and cannot shadow a keyword. Escaping the choice
name is therefore never needed, and it places the
r#in the middle of theaccessor, where it does not parse.
For the same schema C++ generates
type()and Go generatesType..., so Rustwas the only language mangling these names.
Checks
./gradlew runRustTests— 36 passed, 0 failed./gradlew :sbe-tool:test— pass./gradlew :sbe-tool:checkstyleMain :sbe-tool:checkstyleTest— passRegenerating every Rust codec before and after the change leaves all 137
generated files byte-identical except
issue1118/src/flags.rs. Thenon-keyword choice in the new schema, and the existing bit sets such as
OptionalExtras, are unchanged.Reverting only the generator change makes
runRustTestsfail to compile, so thenew schema keeps this covered.