Skip to content

tonic::Result and tonic::Status trigger clippy::result_large_err on rust 1.87 #2253

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

Open
eric-seppanen opened this issue Apr 14, 2025 · 3 comments

Comments

@eric-seppanen
Copy link

Bug Report

While testing the rust 1.87 beta toolchain, I noticed that clippy now raises warnings on any code that uses tonic::Result or otherwise contains a tonic::Status in its Err variant. The result_large_err lint is enabled by default.

I don't have an opinion about whether clippy's thresholds are correct; just wanted to give the tonic developers a heads-up as this will probably trigger warnings in a lot of downstream code that uses tonic.

Version

tonic v0.13.0 (also happens with tonic 0.12.3).

Description

Here's a trivial example that shows the warnings:

pub fn thing1() -> tonic::Result<()> {
    Ok(())
}

cargo +beta clippy says:

warning: the `Err`-variant returned from this function is very large
 --> src/lib.rs:1:19
  |
1 | pub fn hello() -> tonic::Result<()> {
  |                   ^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 176 bytes
  |
  = help: try reducing the size of `tonic::Status`, for example by boxing large elements or replacing it with `Box<tonic::Status>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
  = note: `#[warn(clippy::result_large_err)]` on by default

Or alternatively, without explicitly using tonic::Result but propagating the error type:

pub enum MyError {
    Oops,
    Tonic(tonic::Status),
}

pub fn thing2() -> Result<(), MyError> {
    Ok(())
}
warning: the `Err`-variant returned from this function is very large
 --> src/lib.rs:6:20
  |
3 |     Tonic(tonic::Status),
  |     -------------------- the largest variant contains at least 176 bytes
...
6 | pub fn thing2() -> Result<(), MyError> {
  |                    ^^^^^^^^^^^^^^^^^^^
  |
  = help: try reducing the size of `MyError`, for example by boxing large elements or replacing it with `Box<MyError>`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
  = note: `#[warn(clippy::result_large_err)]` on by default
@LucioFranco
Copy link
Member

We can add this lint to codegen. I would welcome a PR.

@tustvold
Copy link

Have we considered extracting an inner boxed type, e.g. how reqwest handles this - https://docs.rs/reqwest/latest/src/reqwest/error.rs.html#17

@LucioFranco
Copy link
Member

Yeah, my suggestion above was wrong, I think you're probably right @tustvold I would accept a PR for this and I can get a patch release out.

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

No branches or pull requests

3 participants