Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #1156 Prevent error when "Result" is used as name of service in proto #1203

Merged
merged 7 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ members = [
"tests/root-crate-path",
"tests/compression",
"tonic-web/tests/integration",
"tests/service_named_result",
]
14 changes: 14 additions & 0 deletions tests/service_named_result/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "service_named_result"
version = "0.1.0"
edition = "2021"
LucioFranco marked this conversation as resolved.
Show resolved Hide resolved
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.11"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
19 changes: 19 additions & 0 deletions tests/service_named_result/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Lucio Franco
LucioFranco marked this conversation as resolved.
Show resolved Hide resolved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions tests/service_named_result/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/result.proto").unwrap();
}
13 changes: 13 additions & 0 deletions tests/service_named_result/proto/result.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

package result;

service Result {
rpc Listen(google.protobuf.Empty) returns (Reply) {}
}

message Reply {
int32 step = 1;
}
3 changes: 3 additions & 0 deletions tests/service_named_result/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod pb {
tonic::include_proto!("result");
}
8 changes: 4 additions & 4 deletions tonic-build/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn generate_unary<T: Method>(
pub async fn #ident(
&mut self,
request: impl tonic::IntoRequest<#request>,
) -> Result<tonic::Response<#response>, tonic::Status> {
) -> std::result::Result<tonic::Response<#response>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
})?;
Expand All @@ -251,7 +251,7 @@ fn generate_server_streaming<T: Method>(
pub async fn #ident(
&mut self,
request: impl tonic::IntoRequest<#request>,
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
) -> std::result::Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
})?;
Expand All @@ -277,7 +277,7 @@ fn generate_client_streaming<T: Method>(
pub async fn #ident(
&mut self,
request: impl tonic::IntoStreamingRequest<Message = #request>
) -> Result<tonic::Response<#response>, tonic::Status> {
) -> std::result::Result<tonic::Response<#response>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
})?;
Expand All @@ -303,7 +303,7 @@ fn generate_streaming<T: Method>(
pub async fn #ident(
&mut self,
request: impl tonic::IntoStreamingRequest<Message = #request>
) -> Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
) -> std::result::Result<tonic::Response<tonic::codec::Streaming<#response>>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
})?;
Expand Down
14 changes: 7 additions & 7 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(crate) fn generate_internal<T: Service>(
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;

fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}

Expand Down Expand Up @@ -251,14 +251,14 @@ fn generate_trait_methods<T: Service>(
quote! {
#method_doc
async fn #name(&self, request: tonic::Request<#req_message>)
-> Result<tonic::Response<#res_message>, tonic::Status>;
-> std::result::Result<tonic::Response<#res_message>, tonic::Status>;
}
}
(true, false) => {
quote! {
#method_doc
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
-> Result<tonic::Response<#res_message>, tonic::Status>;
-> std::result::Result<tonic::Response<#res_message>, tonic::Status>;
}
}
(false, true) => {
Expand All @@ -270,11 +270,11 @@ fn generate_trait_methods<T: Service>(

quote! {
#stream_doc
type #stream: futures_core::Stream<Item = Result<#res_message, tonic::Status>> + Send + 'static;
type #stream: futures_core::Stream<Item = std::result::Result<#res_message, tonic::Status>> + Send + 'static;

#method_doc
async fn #name(&self, request: tonic::Request<#req_message>)
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
-> std::result::Result<tonic::Response<Self::#stream>, tonic::Status>;
}
}
(true, true) => {
Expand All @@ -286,11 +286,11 @@ fn generate_trait_methods<T: Service>(

quote! {
#stream_doc
type #stream: futures_core::Stream<Item = Result<#res_message, tonic::Status>> + Send + 'static;
type #stream: futures_core::Stream<Item = std::result::Result<#res_message, tonic::Status>> + Send + 'static;

#method_doc
async fn #name(&self, request: tonic::Request<tonic::Streaming<#req_message>>)
-> Result<tonic::Response<Self::#stream>, tonic::Status>;
-> std::result::Result<tonic::Response<Self::#stream>, tonic::Status>;
}
}
};
Expand Down
18 changes: 12 additions & 6 deletions tonic-health/src/generated/grpc.health.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ pub mod health_client {
pub async fn check(
&mut self,
request: impl tonic::IntoRequest<super::HealthCheckRequest>,
) -> Result<tonic::Response<super::HealthCheckResponse>, tonic::Status> {
) -> std::result::Result<
tonic::Response<super::HealthCheckResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
Expand Down Expand Up @@ -143,7 +146,7 @@ pub mod health_client {
pub async fn watch(
&mut self,
request: impl tonic::IntoRequest<super::HealthCheckRequest>,
) -> Result<
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::HealthCheckResponse>>,
tonic::Status,
> {
Expand Down Expand Up @@ -176,10 +179,13 @@ pub mod health_server {
async fn check(
&self,
request: tonic::Request<super::HealthCheckRequest>,
) -> Result<tonic::Response<super::HealthCheckResponse>, tonic::Status>;
) -> std::result::Result<
tonic::Response<super::HealthCheckResponse>,
tonic::Status,
>;
/// Server streaming response type for the Watch method.
type WatchStream: futures_core::Stream<
Item = Result<super::HealthCheckResponse, tonic::Status>,
Item = std::result::Result<super::HealthCheckResponse, tonic::Status>,
>
+ Send
+ 'static;
Expand All @@ -201,7 +207,7 @@ pub mod health_server {
async fn watch(
&self,
request: tonic::Request<super::HealthCheckRequest>,
) -> Result<tonic::Response<Self::WatchStream>, tonic::Status>;
) -> std::result::Result<tonic::Response<Self::WatchStream>, tonic::Status>;
}
#[derive(Debug)]
pub struct HealthServer<T: Health> {
Expand Down Expand Up @@ -256,7 +262,7 @@ pub mod health_server {
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
Expand Down
14 changes: 10 additions & 4 deletions tonic-reflection/src/generated/grpc.reflection.v1alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub mod server_reflection_client {
request: impl tonic::IntoStreamingRequest<
Message = super::ServerReflectionRequest,
>,
) -> Result<
) -> std::result::Result<
tonic::Response<tonic::codec::Streaming<super::ServerReflectionResponse>>,
tonic::Status,
> {
Expand Down Expand Up @@ -248,7 +248,10 @@ pub mod server_reflection_server {
pub trait ServerReflection: Send + Sync + 'static {
/// Server streaming response type for the ServerReflectionInfo method.
type ServerReflectionInfoStream: futures_core::Stream<
Item = Result<super::ServerReflectionResponse, tonic::Status>,
Item = std::result::Result<
super::ServerReflectionResponse,
tonic::Status,
>,
>
+ Send
+ 'static;
Expand All @@ -257,7 +260,10 @@ pub mod server_reflection_server {
async fn server_reflection_info(
&self,
request: tonic::Request<tonic::Streaming<super::ServerReflectionRequest>>,
) -> Result<tonic::Response<Self::ServerReflectionInfoStream>, tonic::Status>;
) -> std::result::Result<
tonic::Response<Self::ServerReflectionInfoStream>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct ServerReflectionServer<T: ServerReflection> {
Expand Down Expand Up @@ -312,7 +318,7 @@ pub mod server_reflection_server {
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
Expand Down