oxidecomputer / oxidecomputer/dropshot

trait-based APIs defined local to a function don't compile

Open
#1,128 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
104
Avg merge
1d 19h
Merged PRs (30d)
22

Description

I expected this to succeed:

fn main() {
    #[dropshot::api_description]
    trait MyApi {
        type Context;
    }
    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()
    );
}

Instead it fails with:

$ cargo run --example=api-trait-broken
   Compiling dropshot v0.12.1-dev (/Users/dap/oxide/dropshot-operation-id/dropshot)
error[E0405]: cannot find trait `MyApi` in this scope
 --> dropshot/examples/api-trait-broken.rs:3:11
  |
3 |     trait MyApi {
  |           ^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0405`.
error: could not compile `dropshot` (example "api-trait-broken") due to 1 previous error

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with dropshot/examples/api-trait-broken.rs and the #[dropshot::api_description] entry point. Run cargo run --example=api-trait-broken to reproduce the local-trait compilation failure, then trace how the macro generates my_api_mod::stub_api_description(). Done means the example compiles and prints the generated OpenAPI JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.