prost icon indicating copy to clipboard operation
prost copied to clipboard

prost-build wrongly thinks extern_path messages can #[derive(Copy)]

Open Sculas opened this issue 9 months ago • 0 comments

Using the following protos/test.proto file:

syntax = "proto3";
package test;
message Uuid {/* external */}

and src/types/mod.rs file:

#[derive(prost::Message, Clone, PartialEq, Eq, Hash)]
pub struct Uuid(#[prost(string, tag = "1")] String);

and build.rs file:

tonic_build::configure()
    .extern_path(".test.Uuid", "::crate::types::Uuid")
    .compile_protos(&["protos/test.proto"], &["protos"])
    .unwrap();

prost-build will think that the Uuid message is copyable, because all() defaults to true for empty iterators:

https://github.com/tokio-rs/prost/blob/df814bbd92a6ab75357317cff079c0e0d3991388/prost-build/src/context.rs#L172-L179

This is obviously wrong, since the Uuid newtype contains a String, which isn't copyable. However, prost-build isn't aware of the extern_path and only sees the empty Uuid message. The current workaround is to specify a string in the message:

syntax = "proto3";
package test;
message Uuid {/* external */ string disallow_copy = 1;}

Note: While both messages are technically the same now, this is just a minimal reproducer to show the bug :)

Sculas avatar Jun 29 '25 16:06 Sculas