Skip to content

codegen: check message and enum names against service-derived items - #333

Merged
iainmcgin merged 1 commit into
mainfrom
message-service-collision
Oct 14, 2026
Merged

iainmcgin merged 1 commit into
mainfrom
message-service-collision

Conversation

@iainmcgin

Copy link
Copy Markdown
Collaborator

Fixes #330.

In connectrpc-build output the service stubs share a Rust module with what buffa puts at the package root: the top-level messages and enums, and a pub use of each message's *View, *OwnedView and, with lazy_views, *LazyView. message GreetClient next to service Greet failed in rustc with E0428, and service PingView next to message Ping with E0255.

A pre-pass lists those names per package, following buffa 0.9.2's rule for which re-exports it keeps; root_types_match_what_buffa_generates compares the list with buffa's output, so a buffa bump that changes the rule fails that test. The list is empty for generate_services, where messages are in another tree.

  • A service type with one of those names is a generation error:

    message pkg.FooClient in b.proto and service pkg.Foo in a.proto both generate Rust identifier `FooClient`; rename one in the proto, or set `type_name_prefix` in the buffa config
    
  • An OwnedFooView alias with one of those names is left out, as it already is when two aliases collide, so message OwnedFooView and message OwnedFoo now compile. The alias is also left out when a service has the name (service OwnedFooView), in both layouts. OwnedFooView then resolves to that other item, so a handler that uses it as the alias gets an error about the other type; the guide says so.

Every schema that is now rejected failed to compile before, with one exception: message FooClient next to service Foo compiled under gate_client_feature while the consumer's client feature was off.

The # Errors sections of generate_files, generate_services and Config::compile also gain conditions that predate this change (a twice-listed file, an invalid client feature name, a bad BUFFA_ELEMENT_MEMORY_LIMIT). Config::buffa_config now says that it resets generate_json, which the type_name_prefix remedy runs into. The [#75] links in the doc comments this touches now point at connectrpc/connect-rust.

In connectrpc-build output the service stubs share a Rust module with
what buffa puts at the package root: the top-level messages and enums,
and a `pub use` of each message's view types. `message GreetClient` next
to `service Greet` failed in rustc with E0428, and `service PingView`
next to `message Ping` with E0255.

List those names per package before the per-service pass, following
buffa's rule for which re-exports it keeps. A service type with one of
the names is a generation error that gives both proto declarations. An
`OwnedFooView` alias with one of the names, or with the name of a
service, is left out, as it already is when two aliases collide.

Fixes #330.

Signed-off-by: Iain McGinniss <309153+iainmcgin@users.noreply.github.com>
@iainmcgin
iainmcgin marked this pull request as ready for review October 13, 2026 23:30
@iainmcgin
iainmcgin enabled auto-merge October 13, 2026 23:53
@iainmcgin
iainmcgin added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 9e8e78a Oct 14, 2026
14 checks passed
@iainmcgin
iainmcgin deleted the message-service-collision branch October 14, 2026 00:23
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

Successfully merging this pull request may close these issues.

codegen: check message and enum names against service-derived items

2 participants