diff --git a/Cargo.toml b/Cargo.toml index 6d2ffea84..1d036a653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,5 +13,6 @@ members = [ "tests/same_name", "tests/wellknown", "tests/extern_path/uuid", + "tests/ambiguous_methods", "tests/extern_path/my_application" ] diff --git a/tests/ambiguous_methods/Cargo.toml b/tests/ambiguous_methods/Cargo.toml new file mode 100644 index 000000000..ecfb3778b --- /dev/null +++ b/tests/ambiguous_methods/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ambiguous_methods" +version = "0.1.0" +authors = ["Yonathan Randolph "] +edition = "2018" +publish = false +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tonic = { path= "../../tonic" } +prost = "0.6" + +[build-dependencies] +tonic-build = { path= "../../tonic-build" } diff --git a/tests/ambiguous_methods/build.rs b/tests/ambiguous_methods/build.rs new file mode 100644 index 000000000..c8a4f961c --- /dev/null +++ b/tests/ambiguous_methods/build.rs @@ -0,0 +1,3 @@ +fn main() { + tonic_build::compile_protos("proto/ambiguous_methods.proto").unwrap(); +} diff --git a/tests/ambiguous_methods/proto/ambiguous_methods.proto b/tests/ambiguous_methods/proto/ambiguous_methods.proto new file mode 100644 index 000000000..8405c9351 --- /dev/null +++ b/tests/ambiguous_methods/proto/ambiguous_methods.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package ambiguous_methods; + +message DropReq {} +message DropResp {} + +// The generated stubs can confuse drop and clone +// with the same method names from Arc, +// resulting in a compile error. +service HelloService { + rpc Drop (DropReq) returns (DropResp); + rpc Clone (DropReq) returns (DropResp); +} + +service HelloStreamingService { + rpc Drop (DropReq) returns (stream DropResp); + rpc Clone (DropReq) returns (stream DropResp); +} diff --git a/tests/ambiguous_methods/src/main.rs b/tests/ambiguous_methods/src/main.rs new file mode 100644 index 000000000..b8673be27 --- /dev/null +++ b/tests/ambiguous_methods/src/main.rs @@ -0,0 +1,8 @@ +#[macro_use] +extern crate tonic; + +tonic::include_proto!("ambiguous_methods"); + +fn main() { + println!("Hello, world!"); +} diff --git a/tonic-build/src/server.rs b/tonic-build/src/server.rs index 5107d3e2a..2ed990f37 100644 --- a/tonic-build/src/server.rs +++ b/tonic-build/src/server.rs @@ -273,7 +273,7 @@ fn generate_unary( fn call(&mut self, request: tonic::Request<#request>) -> Self::Future { let inner = self.0.clone(); let fut = async move { - inner.#method_ident(request).await + (*inner).#method_ident(request).await }; Box::pin(fut) } @@ -326,7 +326,7 @@ fn generate_server_streaming( fn call(&mut self, request: tonic::Request<#request>) -> Self::Future { let inner = self.0.clone(); let fut = async move { - inner.#method_ident(request).await + (*inner).#method_ident(request).await }; Box::pin(fut) @@ -377,7 +377,7 @@ fn generate_client_streaming( fn call(&mut self, request: tonic::Request>) -> Self::Future { let inner = self.0.clone(); let fut = async move { - inner.#method_ident(request).await + (*inner).#method_ident(request).await }; Box::pin(fut) @@ -432,7 +432,7 @@ fn generate_streaming( fn call(&mut self, request: tonic::Request>) -> Self::Future { let inner = self.0.clone(); let fut = async move { - inner.#method_ident(request).await + (*inner).#method_ident(request).await }; Box::pin(fut) }