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

Fix clippy warnings #15

Merged
merged 2 commits into from
May 24, 2020
Merged

Fix clippy warnings #15

merged 2 commits into from
May 24, 2020

Conversation

ArifRoktim
Copy link
Contributor

@ArifRoktim ArifRoktim commented May 17, 2020

Should close #10

@ArifRoktim ArifRoktim marked this pull request as ready for review May 17, 2020 17:39
.github/workflows/main.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@tesuji tesuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike rustfmt, clippy uses conditional compilation to check the code.
So it should be run on all windows, mac and linux.

@ArifRoktim
Copy link
Contributor Author

Clippy on latest stable suggests replacing lines like

self.executable_dir.as_ref().map(|p| p.as_path())

with

self.executable_dir.as_deref()

Option::as_deref was introduced in 1.40.0. I'm thinking about adding
#![allow(clippy::option_as_ref_deref)] with a comment to remove it when msrv is bumped past 1.40.

Copy link
Contributor

@tesuji tesuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime, we are having plan to downgrade Rust version to 1.34.
I would review this PR after we decide.

.github/workflows/main.yml Outdated Show resolved Hide resolved
@ArifRoktim
Copy link
Contributor Author

Different clippy versions were tested by running:

mkdir clippy_versions
for i in 1.{34..42}.0 stable; do
    find -name '*.rs' -execdir touch {} \;
    cargo +${i} clippy --all --all-targets &> clippy_versions/clippy-${i}.txt
done

clippy::option_as_ref_deref, introduced with the clippy that comes with rust 1.42.0, is not compatible with the MSRV until the MSRV is bumped past 1.40.0, so I ignore the lint.
But clippy from rust MSRV until rust 1.41.0 will complain about the lint being unknown, so I also ignore clippy::unknown_clippy_lints.


clippy::redundant_closure in rust 1.34.0 was overzealous and included warnings for closures containing method calls. Since 1.35.0, this lint has been split into two by rust-lang/rust-clippy/pull/4101 and there is now a separate clippy::redundant_closure_for_method_calls that is ignored by default.

directories/src/lib.rs Outdated Show resolved Hide resolved
@tesuji
Copy link
Contributor

tesuji commented May 21, 2020

I suggest using command line flag to allow clippy lint.

@ArifRoktim
Copy link
Contributor Author

Clippy on the command line doesn't seem to heed clippy::unknown_clippy_lints:

$ cargo +1.42.0 clippy --all --all-targets -- -A clippy::option_as_ref_deref
    Checking dirs-sys-next v0.1.0 (/home/arif/git/dirs/dirs-sys)
    Checking directories-next v1.0.0 (/home/arif/git/dirs/directories)
    Checking dirs-next v1.0.0 (/home/arif/git/dirs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.45s

$ cargo +1.41.0 clippy --all --all-targets -- -A clippy::option_as_ref_deref
    Checking dirs-sys-next v0.1.0 (/home/arif/git/dirs/dirs-sys)
error[E0602]: unknown lint: `clippy::option_as_ref_deref`
  |
  = help: did you mean: `clippy::option_unwrap_used`
  = note: requested on the command line with `-A clippy::option_as_ref_deref`

error[E0602]: unknown lint: `clippy::option_as_ref_deref`
  |
  = help: did you mean: `clippy::option_unwrap_used`
  = note: requested on the command line with `-A clippy::option_as_ref_deref`

error: aborting due to previous error
<snip>

$ cargo +1.41.0 clippy --all --all-targets -- -A clippy::unknown_clippy_lints -A clippy::option_as_ref_deref
    Checking dirs-sys-next v0.1.0 (/home/arif/git/dirs/dirs-sys)
error[E0602]: unknown lint: `clippy::option_as_ref_deref`
  |
  = help: did you mean: `clippy::option_unwrap_used`
  = note: requested on the command line with `-A clippy::option_as_ref_deref`

error[E0602]: unknown lint: `clippy::option_as_ref_deref`
  |
  = help: did you mean: `clippy::option_unwrap_used`
  = note: requested on the command line with `-A clippy::option_as_ref_deref`

error: aborting due to previous error
<snip>

Plus if in the code itself, the output when users run clippy in the repo will be the same as that of the CI.

@tesuji
Copy link
Contributor

tesuji commented May 23, 2020

How about using clippy of nightly toolchain? This way we don't have to allow clippy::unknown_clippy_lints.

Fix the clippy warnings under:
* `clippy::or_fun_call`
* `clippy::redundant_clone`.
Clippy that comes with rust 1.42.0 and later has the
`clippy::option_as_ref_deref` lint enabled by default. Fixing the lint
requires an MSRV bump past 1.40.0. Allow the lint until then.
@ArifRoktim
Copy link
Contributor Author

Whoops, I think I misunderstood what you wanted. I was trying to make it so that users who ran clippy on the shell using any version from the MSRV to the current stable didn't get extraneous warnings, which is why I added the #![allow(clippy::<lint>)] in the source files.

I think you're only concerned about the CI. If that's the case, then the latest stable is all that's needed. All of os: [ubuntu-latest, macos-latest, windows-latest] use 1.43.0+, so it should be fine to just do:
cargo clippy --all --all-targets -- -A clippy::option_as_ref_deref.

@tesuji
Copy link
Contributor

tesuji commented May 24, 2020

Yes, I don't think it is useful to use old clippy for linting.

Copy link
Contributor

@tesuji tesuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ArifRoktim

@tesuji

This comment has been minimized.

1 similar comment
@tesuji

This comment has been minimized.

@tesuji
Copy link
Contributor

tesuji commented May 24, 2020

bors has often crashed recently. Merge manually I think.

@tesuji tesuji merged commit fc56545 into xdg-rs:master May 24, 2020
@ArifRoktim ArifRoktim deleted the clippy_lints branch May 24, 2020 05:05
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 this pull request may close these issues.

Fixing clippy warnings
2 participants