google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
23.17k stars 3.24k forks source link

Conflicts with Rust `core` module in code generated by flatc 23.5.26. #8209

Closed olson-dan closed 2 months ago

olson-dan commented 9 months ago

I'm using flatc.exe on Windows version 23.5.26, generating code for Rust.

The first line of the .fbs I'm attempting to compile is:

namespace assetstore.core;

This generates Rust code similar to the following:

#[allow(unused_imports, dead_code)]
pub mod assetstore {

    use core::cmp::Ordering;
    use core::mem;

    extern crate flatbuffers;
    use self::flatbuffers::{EndianScalar, Follow};
    #[allow(unused_imports, dead_code)]
    pub mod core {

        use core::cmp::Ordering;
        use core::mem;

        extern crate flatbuffers;
        use self::flatbuffers::{EndianScalar, Follow};

This causes conflicts with the Rust core module:

error[E0432]: unresolved import `core::cmp`
  --> src\..\target\flatbuffers\core_generated.rs:14:15
   |
14 |     use core::cmp::Ordering;
   |               ^^^ could not find `cmp` in `core`

error[E0603]: module import `mem` is private
   --> src\..\target\flatbuffers\core_generated.rs:15:15
    |
15  |     use core::mem;
    |               ^^^ private module import
    |
note: the module import `mem` is defined here...
   --> src\..\target\flatbuffers\core_generated.rs:23:13
    |
23  |         use core::mem;

Changing the boilerplate to use ::core::cmp::Ordering; and use ::core::mem; fixes the issue.

I recognize that I can also change the name inside the schema, but this is part of a large corpus of fbs files that I only partially control.

nihohit commented 8 months ago

looks related to https://github.com/google/flatbuffers/issues/8148 which can probably be fixed just by releasing a version.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] commented 2 months ago

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.