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

Build warnings in proto defs #295

Closed
hntd187 opened this issue Mar 14, 2020 · 4 comments · Fixed by #296
Closed

Build warnings in proto defs #295

hntd187 opened this issue Mar 14, 2020 · 4 comments · Fixed by #296
Labels
A-build C-bug Category: Something isn't working

Comments

@hntd187
Copy link

hntd187 commented Mar 14, 2020

Bug Report

Version

0.1.1

Platform

All (happens on windows, osx and linux)

Description

I get build warnings like the following

warning: type `raft_requestSvc` should have an upper camel case name
   --> C:\Users\shcar\IdeaProjects\Toshi\target\debug\build\toshi-proto-979910a1e8f4b4da\out/clusterrpc.rs:574:28
    |
574 |                     struct raft_requestSvc<T: IndexService>(pub Arc<T>);
    |                            ^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `RaftRequestSvc`

warning: type `joinSvc` should have an upper camel case name
   --> C:\Users\shcar\IdeaProjects\Toshi\target\debug\build\toshi-proto-979910a1e8f4b4da\out/clusterrpc.rs:601:28
    |
601 |                     struct joinSvc<T: IndexService>(pub Arc<T>);
    |                            ^^^^^^^ help: convert the identifier to upper camel case: `JoinSvc`

My proto def can be found here.
https://github.com/toshi-search/Toshi/blob/master/toshi-proto/proto/cluster.proto

@LucioFranco LucioFranco added C-bug Category: Something isn't working A-build labels Mar 18, 2020
@jen20
Copy link
Collaborator

jen20 commented Mar 19, 2020

Hi @hntd187! Thanks for opening a bug report. This reproduces easily using the latest release of tonic and tonic-build. The issue is caused by service_ident in the various generated files being derived from the gRPC method identifier, for example:

let service_ident = quote::format_ident!("{}Svc", method.identifier());

There seem to be two approaches to resolving this:

  • Transform the method identifier from the conventional gRPC lower snake case into the upper camel case expected by Rust type names when generating service_ident. My hunch is that this is OK, but I'm not 100% certain this could never lead to duplicate type names in a protocol buffers package with names constructed in some manner.

  • Annotate the type names to allow non-conventional type names (using #[allow(non_camel_case_types)]) - since the structures in question are never exposed in public APIs anyway, this seems less invasive and could be build directly into the templates.

@LucioFranco Any thoughts on which approach you'd prefer here?

@LucioFranco
Copy link
Member

@jen20 the allow solution should be fine 👍 its quick and easy.

@LucioFranco
Copy link
Member

Also to note, this change will go out with 0.2 which is slightly on hold for the moment, so when this gets fixed on master I'd suggest users to work off of master for a bit.

jen20 added a commit that referenced this issue Mar 19, 2020
This commit adjusts the code generation for the internal structs in the
implementation of Service<http::Request<HyperBody>> for *Server<T> in
order to annotate internal structs whose names are derived from gRPC
method names with `[allow(non_camel_case_types)]`. This supresses
compiler warnings about type names when compiling generated code. The
struct names are not exposed externally, so this has no impact on types
seen by library consumers.

Fixes #295.
jen20 added a commit that referenced this issue Mar 19, 2020
This commit adjusts the code generation for the internal structs in the
implementation of Service<http::Request<HyperBody>> for *Server<T> in
order to annotate internal structs whose names are derived from gRPC
method names with `[allow(non_camel_case_types)]`. This supresses
compiler warnings about type names when compiling generated code. The
struct names are not exposed externally, so this has no impact on types
seen by library consumers.

Fixes #295.
jen20 added a commit that referenced this issue Mar 19, 2020
This commit adjusts the code generation for the internal structs in the
implementation of Service<http::Request<HyperBody>> for *Server<T> in
order to annotate internal structs whose names are derived from gRPC
method names with `[allow(non_camel_case_types)]`. This supresses
compiler warnings about type names when compiling generated code. The
struct names are not exposed externally, so this has no impact on types
seen by library consumers.

Fixes #295.
@bmulder-innoseis
Copy link

bmulder-innoseis commented May 31, 2022

this also happens in streaming calls.
proto:

service Foo {
    rpc bar (barRequest) returns (stream barResponse);
}

generated server code:

pub mod foo_server {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
    use tonic::codegen::*;
    ///Generated trait containing gRPC methods that should be implemented for use with FooServer.
    #[async_trait]
    pub trait Foo: Send + Sync + 'static {
        ///Server streaming response type for the bar method.
        type barStream: futures_core::Stream<
                Item = Result<super::BarResponse, tonic::Status>,
            >
            + Send
            + 'static;
        [...]
    }
}

when compiling:

    |
135 |         type barStream: futures_core::Stream<
    |              ^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `BarStream`
    |
    = note: `#[warn(non_camel_case_types)]` on by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build C-bug Category: Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants