oxidecomputer / oxidecomputer/progenitor

progenitor sometimes produces code which triggers `clippy::unnecessary_to_owned`

Open
#218 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
136
Avg merge
8h 36m
Merged PRs (30d)
14

Description

    ///Swagger Endpoint
    ///
    ///Swagger docs (UI)
    ///
    ///Sends a `GET` request to `/docs/{proxy}`
    pub async fn get_swagger_docs_proxy<'a>(
        &'a self,
        proxy: &'a str,
    ) -> Result<ResponseValue<()>, Error<()>> {
        let url = format!("{}/docs/{}", self.baseurl, encode_path(&proxy.to_string()),);

Clippy output:

warning: unnecessary use of `to_string`
    --> src/codegen.rs:1636:67
     |
1636 |         let url = format!("{}/docs/{}", self.baseurl, encode_path(&proxy.to_string()),);
     |                                                                   ^^^^^^^^^^^^^^^^^^ help: use: `proxy`
     |
     = note: `#[warn(clippy::unnecessary_to_owned)]` on by default
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned

Swagger def:

    "/docs/{proxy}": {
      "get": {
        "tags": [
          "swagger"
        ],
        "summary": "Swagger Endpoint",
        "operationId": "getSwaggerDocsProxy",
        "description": "Swagger docs (UI)",
        "parameters": [
          {
            "name": "proxy",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "swagger UI"
          }
        }
      }
    },

To be clar: this seems a bit worse than the other warnings. This is an extra unnecessary allocation.

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 in src/codegen.rs around line 1636 and inspect how path parameters are passed to encode_path. Reproduce the generated get_swagger_docs_proxy method from the Swagger definition in the issue, then run Clippy; done means the generated Rust no longer triggers unnecessary_to_owned for this parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.