• Max Burke's avatar
    Bugfix for Rust generation of union fields named with language keywords (#5592) · eddebec1
    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
    eddebec1
Name
Last commit
Last update
.appveyor Loading commit data...
.bazelci Loading commit data...
.github Loading commit data...
.travis Loading commit data...
CMake Loading commit data...
android Loading commit data...
conan Loading commit data...
dart Loading commit data...
docs Loading commit data...
go Loading commit data...
grpc Loading commit data...
include/flatbuffers Loading commit data...
java/com/google/flatbuffers Loading commit data...
js Loading commit data...
lobster Loading commit data...
lua Loading commit data...
net/FlatBuffers Loading commit data...
php Loading commit data...
python Loading commit data...
reflection Loading commit data...
rust/flatbuffers Loading commit data...
samples Loading commit data...
snap Loading commit data...
src Loading commit data...
tests Loading commit data...
.clang-format Loading commit data...
.editorconfig Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.travis.yml Loading commit data...
BUILD Loading commit data...
CMakeLists.txt Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE.txt Loading commit data...
WORKSPACE Loading commit data...
appveyor.yml Loading commit data...
build_defs.bzl Loading commit data...
composer.json Loading commit data...
conanfile.py Loading commit data...
package.json Loading commit data...
pom.xml Loading commit data...
readme.md Loading commit data...