codegen: an RPC named `Config`, `ConfigMut` or `New` collides with the generated client's inherent methods (E0592)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start in connectrpc-codegen/src/codegen.rs: read check_method_collisions and inspect the generated client impl block. Compare the collision checks with the generated new, config and config_mut methods; the issue leaves the long-term fix open. Done means a colliding RPC is handled deliberately, rather than failing with E0592 in generated code.
Written by the indexing model from the issue text.
Description
The generated FooClient<T> has three inherent methods of its own, new,
config and config_mut, in the same impl block as one method per RPC. An
RPC whose snake_case name is one of those emits a second definition, and the
crate fails to compile:
error[E0592]: duplicate definitions with name `config`
--> .../out/repro.__connect.rs:386:5
|
378 | pub fn config(&self) -> &::connectrpc::client::ClientConfig {
| ----------------------------------------------------------- other definition for `config`
...
386 | / pub async fn config(
387 | | &self,
388 | | request: Req,
... |
394 | | > {
| |_____^ duplicate definitions for `config`
ConfigMut gives the same error for config_mut, and New for new.
This shows up in real protos: opencensus.proto.agent.trace.v1.TraceService
has rpc Config(stream CurrentLibraryConfig) returns (stream UpdatedLibraryConfig).
check_method_collisions (from #28) catches RPCs that collide with each other,
and #280 extended the check across services that share a module. Neither
checks RPC names against the client's own methods, so the failure is reported
in generated code instead of in the proto.
Reproduction
connectrpc 0.9.1, connectrpc-build 0.9.0. The same code is on main at
bd2ab67 (connectrpc-codegen/src/codegen.rs, the client impl block).
Cargo.toml:
[package]
name = "repro"
version = "0.0.0"
edition = "2024"
publish = false
[dependencies]
buffa = { version = "0.9.2", features = ["json"] }
connectrpc = { version = "0.9.1", features = ["client"] }
serde = { version = "1", features = ["derive"] }
[build-dependencies]
connectrpc-build = "0.9.0"
proto/repro.proto:
syntax = "proto3";
package repro;
message Req {}
message Resp {}
service Trace {
rpc Config(Req) returns (Resp);
}
build.rs:
fn main() {
connectrpc_build::Config::new()
.files(&["proto/repro.proto"])
.includes(&["proto"])
.include_file("_connectrpc.rs")
.compile()
.unwrap();
}
src/lib.rs:
include!(concat!(env!("OUT_DIR"), "/_connectrpc.rs"));
cargo check fails with the E0592 above.
Possible fixes
- Rename the client's accessors where they collide. Keep the RPC methods
named after the RPCs, matching the server trait, and emit the accessors
under another name (e.g.client_config/client_config_mut) only in
clients that need it. Callers can work around the bug this way today by
post-processing the generated code. It makes the accessor name vary by service, so it
probably isn't the right long-term answer. - Move the accessors off the inherent namespace. For example, put them on a
trait (ClientConfigExt::config(&client)) or make them associated
functions (FooClient::config(&client)). Either way an RPC can never
collide with them. This is a breaking change. - Rename the RPC method where it collides, for example
config_rpc. This
keeps the accessors, but the client method no longer matches the server
trait's method name. - At least reject it clearly. Treat
new,configandconfig_mutas
taken incheck_method_collisions, so codegen fails with "RPCConfigcollides with the generated client's
config()" instead of E0592 in generated code.
New can't be fixed by renaming the constructor without breaking every
client, so (4) is probably right for new whatever is chosen for
config/config_mut.
- Dominant language
- Rust
- Stars
- 544
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from connectrpc/connect-rust
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
connectrpc/connect-rust#360 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
connectrpc/connect-rust#358 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 53/100
connectrpc/connect-rust#355 ·
-
Streaming request body errors are always reported as `internal`Possibly taken @AhmedElBanna80 claimed this 18 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
connectrpc/connect-rust#352 ·
-
Difficulty 3/5 Half a day Newbie friendliness 48/100
connectrpc/connect-rust#349 ·
All issues in connectrpc/connect-rust
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
Maintainers usually reply within 17 days
-
bug rust SDK & CLI & REST API
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
boxlite-ai/boxlite#3292 ·
Maintainers usually reply within 1 day
-
Android bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
anefzaoui/misterdownloadmanager#2516 ·
Maintainers usually reply within 1 day
-
editor ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
state:triage tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 89/100
agent8-cash/ethpayserver#731 ·
Maintainers usually reply within 1 day