• Max Burke's avatar
    [rust] Make enum names public (#5690) · 355dfd48
    Max Burke authored
    * Bugfix for Rust generation of union fields named with language keywords
    
    Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
    
    For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
    
    When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
    
    ```
      #[inline]
      #[allow(non_snake_case)]
      pub fn type__as_int(&self) -> Option<Int<'a>> {
        if self.type__type() == Type::Int {
          self.type_().map(|u| Int::init_from_table(u))
        } else {
          None
        }
      }
    ```
    
    Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
    
    * [Rust] Add crate-relative use statements for FBS includes.
    
    At present if a flatbuffer description includes a reference to a type in
    another file, the generated Rust code needs to be hand-modified to add
    the appropriate `use` statements.
    
    This assumes that the dependencies are built into the same crate, which
    I think is a reasonable assumption?
    
    * Revert "[Rust] Add crate-relative use statements for FBS includes."
    
    This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
    
    * Address comments raised in PR
    
    * Update documentation comments per feedback
    
    * Fix typo
    
    * [rust] Make enum variant names public.
    
    * Update generated test files
    
    * Add test for public enum names
    355dfd48
Name
Last commit
Last update
..
FlatBuffers.Benchmarks Loading commit data...
FlatBuffers.Test Loading commit data...
MyGame Loading commit data...
cpp17 Loading commit data...
docker Loading commit data...
evolution_test Loading commit data...
fuzzer Loading commit data...
include_test Loading commit data...
namespace_test Loading commit data...
prototest Loading commit data...
rust_usage_test Loading commit data...
union_vector Loading commit data...
BUILD Loading commit data...
DartTest.sh Loading commit data...
GoTest.sh Loading commit data...
JavaScriptTest.js Loading commit data...
JavaScriptTest.sh Loading commit data...
JavaScriptUnionVectorTest.js Loading commit data...
JavaTest.bat Loading commit data...
JavaTest.java Loading commit data...
JavaTest.sh Loading commit data...
KotlinTest.kt Loading commit data...
KotlinTest.sh Loading commit data...
LuaTest.bat Loading commit data...
LuaTest.sh Loading commit data...
PythonTest.sh Loading commit data...
RustTest.bat Loading commit data...
RustTest.sh Loading commit data...
TestAll.sh Loading commit data...
TypeScriptTest.sh Loading commit data...
arrays_test.bfbs Loading commit data...
arrays_test.fbs Loading commit data...
arrays_test.golden Loading commit data...
arrays_test.schema.json Loading commit data...
arrays_test_generated.h Loading commit data...
generate_code.bat Loading commit data...
generate_code.sh Loading commit data...
go_test.go Loading commit data...
javatest.bin Loading commit data...
lobstertest.lobster Loading commit data...
luatest.lua Loading commit data...
monster_extra.fbs Loading commit data...
monster_extra_generated.h Loading commit data...
monster_test.bfbs Loading commit data...
monster_test.fbs Loading commit data...
monster_test.grpc.fb.cc Loading commit data...
monster_test.grpc.fb.h Loading commit data...
monster_test.schema.json Loading commit data...
monster_test_generated.h Loading commit data...
monster_test_generated.js Loading commit data...
monster_test_generated.lobster Loading commit data...
monster_test_generated.rs Loading commit data...
monster_test_generated.ts Loading commit data...
monster_test_my_game.example2_generated.dart Loading commit data...
monster_test_my_game.example_generated.dart Loading commit data...
monster_test_my_game_generated.dart Loading commit data...
monsterdata_extra.json Loading commit data...
monsterdata_python_wire.mon Loading commit data...
monsterdata_test.golden Loading commit data...
monsterdata_test.json Loading commit data...
monsterdata_test.mon Loading commit data...
native_type_test.fbs Loading commit data...
native_type_test_generated.h Loading commit data...
native_type_test_impl.cpp Loading commit data...
native_type_test_impl.h Loading commit data...
phpTest.php Loading commit data...
phpUnionVectorTest.php Loading commit data...
phpUnionVectorTest.sh Loading commit data...
py_test.py Loading commit data...
test.cpp Loading commit data...
test_assert.cpp Loading commit data...
test_assert.h Loading commit data...
test_builder.cpp Loading commit data...
test_builder.h Loading commit data...
unicode_test.json Loading commit data...