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

[rust-server] Fix clippy warnings #13907

Merged

Conversation

siketyan
Copy link
Contributor

@siketyan siketyan commented Nov 4, 2022

This pull request fixes these clippy warnings:

  • clippy::disallowed_names (renamed from clippy::blacklisted_name)
  • clippy::single_match (dismissed because it occurs in some cases)
  • clippy::explicit_auto_deref
  • clippy::needless_borrow
  • clippy::suspicious_to_owned

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@frol @farcaller @richardwhiuk @paladinzh @jacob-pro

@siketyan
Copy link
Contributor Author

siketyan commented Nov 5, 2022

I have just published a built Docker image on rev 5de15fb (only for Arm64, sorry!).
Please take a look if you want to test the new behaviour of rust-server generator.
Thank you!

https://github.com/yumemi-inc/openapi-generator/pkgs/container/openapi-generator/48974185?tag=v6.3.0-SNAPSHOT

@wing328 wing328 added this to the 6.3.0 milestone Nov 7, 2022
@wing328
Copy link
Member

wing328 commented Nov 7, 2022

when testing it locally, I got the following errors in the rust-server sample:

error: unknown lint: `clippy::disallowed_names`
 --> output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs:3:48
  |
3 | #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
  |                                                ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::disallowed_types`

error: unknown lint: `clippy::disallowed_names`
 --> output/no-example-v3/src/lib.rs:3:48
  |
3 | #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
  |                                                ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::disallowed_types`

error: unknown lint: `clippy::disallowed_names`
 --> output/rust-server-test/src/lib.rs:3:48
  |
3 | #![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)]
  |                                                ^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::disallowed_types`

error: could not compile `no-example-v3` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `multipart-v3` due to 2 previous errors
error: could not compile `rust-server-test` due to 2 previous errors
error: use of a blacklisted/placeholder name `foo`
    --> output/petstore-with-fake-endpoints-models-for-testing/src/models.rs:3101:36
     |
3101 |             self.foo.as_ref().map(|foo| {
     |                                    ^^^
     |
     = note: `-D clippy::blacklisted-name` implied by `-D warnings`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

error: use of a blacklisted/placeholder name `baz`
    --> output/petstore-with-fake-endpoints-models-for-testing/src/models.rs:5081:36
     |
5081 |             self.baz.as_ref().map(|baz| {
     |                                    ^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name

error: could not compile `petstore-with-fake-endpoints-models-for-testing` due to 4 previous errors
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12:34 min
[INFO] Finished at: 2022-11-07T21:56:55+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (clippy) on project RustServerTests: Command execution failed.: Process exited with an error: 101 (Exit value: 101) -> [Help 1]

can you please take a look when you've time?

@siketyan
Copy link
Contributor Author

siketyan commented Nov 7, 2022

@wing328
It is a version mismatch of clippy.
As described in the description, clippy renamed the lint recently.
In fact, I have tested it works on my local environment.

I think there is no way to support both version of clippy for allowing or denying lints, so we need to decide to support the latest only or keep the current behaviour.

How do you think about that?

@jacob-pro
Copy link
Contributor

@wing328 I think we need to consider pinning the project to fixed version of clippy and Rust in general. Otherwise what will happen is our CI checks may fail in future even though the code hasn't changed. I mentioned this before here:
#13473 (comment)

We need to define a MSRV and have the CI install this fixed version

@siketyan
Copy link
Contributor Author

siketyan commented Nov 8, 2022

I apologise I missed your comments in the previous pull request.

I agree that we should set MSRV for supporting and testing. Since clippy is intended to use in project-local, there is no backward compatibility as shown as the testing result now. To keep the MSRV older (it means the warnings are continuously shown in later toolchains), or to keep later (older toolchains will not be supported) is an important decision I think.

@wing328
Copy link
Member

wing328 commented Nov 8, 2022

I think we need to consider pinning the project to fixed version of clippy and Rust in general.

the suggestion sounds good.

@wing328 wing328 modified the milestones: 6.3.0, 6.3.1 Jan 20, 2023
@siketyan
Copy link
Contributor Author

Any updates on this?

We have an additional warnings x37 times since v1.67:

warning: variables can be used directly in the `format!` string
  --> src/client/mod.rs:57:39
   |
57 |     let port = uri.port_u16().map(|x| format!(":{}", x)).unwrap_or_default();
   |                                       ^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
   = note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
   |
57 -     let port = uri.port_u16().map(|x| format!(":{}", x)).unwrap_or_default();
57 +     let port = uri.port_u16().map(|x| format!(":{x}")).unwrap_or_default();
   |

@wing328
Copy link
Member

wing328 commented Feb 17, 2023

can you please PM me via slack next week to discuss how to move forward with this?

have a nice weekend.

@wing328 wing328 modified the milestones: 6.4.0, 6.5.0 Feb 19, 2023
@wing328
Copy link
Member

wing328 commented Feb 20, 2023

tests passed via #14758.

we'll merge and see if later someone can contribute a PR or two to improve the CI tests.

@wing328 wing328 merged commit 9290c1a into OpenAPITools:master Feb 20, 2023
@wing328
Copy link
Member

wing328 commented Feb 20, 2023

and as a workaround, users can enable/disable the warnings: https://doc.rust-lang.org/nightly/clippy/usage.html

@siketyan siketyan deleted the rust-server/fix-clippy-warnings branch February 20, 2023 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants