Skip to content

Enum variant collisions #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomjakubowski opened this issue Apr 27, 2014 · 1 comment
Closed

Enum variant collisions #21

tomjakubowski opened this issue Apr 27, 2014 · 1 comment

Comments

@tomjakubowski
Copy link

A protobuf file like this:

message MessageA {
  enum EnumA { FOO = 0; }
}
message MessageB {
  enum EnumB { FOO = 0; }
}

generates Rust like:

#[deriving(Clone,Eq,Show)]
pub enum MessageA_EnumA {
    FOO = 0,
}

#[deriving(Clone,Eq,Show)]
pub enum MessageB_EnumB {
    FOO = 0,
}

Since Rust doesn't have scoped enums (and won't until after 1.0), a workaround for this might be to place protobuf messages into their own Rust modules. protoc enforces that enum values must be unique within messages, e.g. this:

message MessageA {
  enum EnumA { FOO = 0; }
  enum EnumB { FOO = 0; }
}

fails to compile with:

foo.proto:3:18: "FOO" is already defined in "MessageA".
foo.proto:3:18: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "FOO" must be unique within "MessageA", not just within "EnumB".
tomjakubowski added a commit to tomjakubowski/rethinkdb-rs that referenced this issue Apr 27, 2014
This version will not produce correct Rust with rust-protobuf (see
stepancheg/rust-protobuf#21). Could be a good idea instead to write an
awk script or something to munge constants from the .proto into a Rust
source file, since we won't actually be using protobufs over the wire.
@stepancheg
Copy link
Owner

@tomjakubowski fixed in db55952, thanks!

jxs pushed a commit to jxs/rust-protobuf that referenced this issue Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants