tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.69k stars 481 forks source link

Module generated for 'oneof' field conflicts with module generated for package #1004

Open kriomant opened 4 months ago

kriomant commented 4 months ago

Here is reduced copy of what I met in .proto files of real service. This service is out of my control, I just want to create client for it.

proto/foo.proto

syntax = "proto3";

package foo;

import "foo/bar.proto";

message Bar {
  oneof bar {
    bar.This this = 1;
    bar.That that = 2;
  }
}

proto/foo/bar.proto

syntax = "proto3";

package foo.bar;

message This {}
message That {}

src/lib.rs

pub mod foo {
    include!(concat!(env!("OUT_DIR"), "/foo.rs"));
    pub mod bar {
        include!(concat!(env!("OUT_DIR"), "/foo.bar.rs"));
    }
}

Such proto files lead to error:

error[E0428]: the name `bar` is defined multiple times
 --> /Users/kriomant/.cargo/target/debug/build/proto-67d1c5fed5b166e2/out/foo.rs:8:1
  |
8 | pub mod bar {
  | ^^^^^^^^^^^ `bar` redefined here
  |
 ::: src/lib.rs:3:5
  |
3 |     pub mod bar {
  |     ----------- previous definition of the module `bar` here
  |
  = note: `bar` must be defined only once in the type namespace of this module

This is because each message with 'oneof' field generates module with name corresponding to that message name. In this case it conflicts with existing proto package.