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

spurious dead code warning with trait-based API definition #1129

Closed
davepacheco opened this issue Oct 2, 2024 · 1 comment · Fixed by #1137
Closed

spurious dead code warning with trait-based API definition #1129

davepacheco opened this issue Oct 2, 2024 · 1 comment · Fixed by #1137

Comments

@davepacheco
Copy link
Collaborator

With this code (a version of the code from #1128 where I've moved the trait definition to the top level):

#[dropshot::api_description]
trait MyApi {
    type Context;
}
fn main() {
    let description = my_api_mod::stub_api_description().unwrap();
    let spec = description.openapi("Counter Server", "1.0.0");
    println!(
        "{}",
        serde_json::to_string_pretty(&spec.json().unwrap()).unwrap()
    );
}

When I run it, it works, but I get this when compiling it:

dap@zathras dropshot-operation-id $ cargo version
cargo 1.81.0 (2dbb1af80 2024-08-20)
dap@zathras dropshot-operation-id $ cargo check --example=api-trait-broken
    Checking dropshot v0.12.1-dev (/Users/dap/oxide/dropshot-operation-id/dropshot)
warning: trait `MyApi` is never used
 --> dropshot/examples/api-trait-broken.rs:2:7
  |
2 | trait MyApi {
  |       ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `dropshot` (example "api-trait-broken") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.56s

I get that technically the trait itself is unused but I think from a Dropshot user's perspective this warning is spurious and we should silence it if we can.

@sunshowers
Copy link
Contributor

Oh interesting -- yeah we should silence this.

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

Successfully merging a pull request may close this issue.

2 participants