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

progenitor sometimes produces code which triggers clippy::unnecessary_to_owned #218

Open
Fishrock123 opened this issue Oct 17, 2022 · 2 comments

Comments

@Fishrock123
Copy link

Fishrock123 commented Oct 17, 2022

    ///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.

@ahl
Copy link
Collaborator

ahl commented Oct 17, 2022

Thanks for the bug and the simple reproduction case!

@ahl
Copy link
Collaborator

ahl commented Dec 24, 2024

I think #1017 may inadvertently be addressing 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

No branches or pull requests

2 participants