Skip to content

Fix all clippy and rustc warnings (beta toolchain version 0.1.77) #345

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

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

primeos-work
Copy link
Member

@primeos-work primeos-work commented Feb 19, 2024

The suspicious_open_options lint 0 warns that the truncation behaviour should be made explicit when creating new files. We also set create_new(true), which ensures that a new file will always be created so we should simply drop create(true) since it has no effect anyway: "If .create_new(true) is set, .create() and .truncate() are ignored." 1

The unconditional_recursion lint 2 also emits a warning but that's a false positive and should already be fixed in nightly (see 3 for a very similar case and 4 for the PR that should fix it). In our case we're comparing tuples with just two fields of the Package structure so it isn't recursive.


This fixes the following clippy warnings:

[rustup@groot butido]$ cargo clippy --release
   Compiling butido v0.4.0 (/home/rustup/butido)
warning: file opened with `create`, but `truncate` behavior not defined
   --> src/endpoint/scheduler.rs:515:22
    |
515 |                     .create(true)
    |                      ^^^^^^^^^^^^- help: add: `.truncate(true)`
    |
    = help: if you intend to overwrite an existing file entirely, call `.truncate(true)`
    = help: if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`
    = help: alternatively, use `.append(true)` to append to the file instead of overwriting it
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options
    = note: `#[warn(clippy::suspicious_open_options)]` on by default

warning: function cannot return without recursing
   --> src/package/package.rs:224:5
    |
224 | /     fn eq(&self, other: &Package) -> bool {
225 | |         (self.name(), self.version()).eq(&(other.name(), other.version()))
226 | |     }
    | |_____^
    |
note: recursive call site
   --> src/package/package.rs:225:9
    |
225 |         (self.name(), self.version()).eq(&(other.name(), other.version()))
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
    = note: `#[warn(clippy::unconditional_recursion)]` on by default

warning: file opened with `create`, but `truncate` behavior not defined
   --> src/source/mod.rs:138:14
    |
138 |             .create(true)
    |              ^^^^^^^^^^^^- help: add: `.truncate(true)`
    |
    = help: if you intend to overwrite an existing file entirely, call `.truncate(true)`
    = help: if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`
    = help: alternatively, use `.append(true)` to append to the file instead of overwriting it
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options

warning: `butido` (bin "butido") generated 3 warnings
    Finished release [optimized] target(s) in 12.57s

The `suspicious_open_options` lint [0] warns that the truncation
behaviour should be made explicit when creating new files. We also set
`create_new(true)`, which ensures that a new file will *always* be
created so we should simply drop `create(true)` since it has no effect
anyway: "If `.create_new(true)` is set, `.create()` and `.truncate()`
are ignored." [1]

The `unconditional_recursion` lint [2] also emits a warning but that's a
false positive and should already be fixed in nightly (see [3] for a
very similar case and [4] for the PR that should fix it).
In our case we're comparing tuples with just two fields of the `Package`
structure so it isn't recursive.

[0]: https://rust-lang.github.io/rust-clippy/master/index.html#/suspicious_open_options
[1]: https://docs.rs/tokio/1.34.0/tokio/fs/struct.OpenOptions.html#method.create_new
[2]: https://rust-lang.github.io/rust-clippy/master/index.html#/unconditional_recursion
[3]: rust-lang/rust-clippy#12133
[4]: rust-lang/rust-clippy#12137

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
@primeos-work primeos-work added this pull request to the merge queue Feb 19, 2024
Merged via the queue into science-computing:master with commit 3c66d60 Feb 19, 2024
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.

1 participant