Skip to content

Apply some useful pedantic rules into project #4949

@qarmin

Description

@qarmin

Looks that a lot of pedantic rules are really useful to improve/unify style.
Command of manually chosen clippy rules

cargo clippy -- -Wclippy::bool_to_int_with_if -Wclippy::checked_conversions -Wclippy::cloned_instead_of_copied -Wclippy::explicit_deref_methods -Wclippy::explicit_into_iter_loop -Wclippy::explicit_iter_loop -Wclippy::filter_map_next -Wclippy::flat_map_option -Wclippy::float_cmp -Wclippy::from_iter_instead_of_collect -Wclippy::if_not_else -Wclippy::implicit_clone -Wclippy::inconsistent_struct_constructor -Wclippy::inefficient_to_string -Wclippy::invalid_upcast_comparisons -Wclippy::iter_not_returning_iterator -Wclippy::large_digit_groups -Wclippy::large_stack_arrays -Wclippy::large_types_passed_by_value -Wclippy::linkedlist -Wclippy::macro_use_imports -Wclippy::manual_assert -Wclippy::manual_instant_elapsed -Wclippy::manual_let_else -Wclippy::manual_ok_or -Wclippy::manual_string_new -Wclippy::map_unwrap_or -Wclippy::match_bool -Wclippy::match_same_arms -Wclippy::match_wildcard_for_single_variants -Wclippy::maybe_infinite_iter -Wclippy::mismatching_type_param_order -Wclippy::mut_mut -Wclippy::naive_bytecount -Wclippy::needless_bitwise_bool -Wclippy::needless_continue -Wclippy::needless_for_each -Wclippy::needless_pass_by_value -Wclippy::no_effect_underscore_binding -Wclippy::range_minus_one -Wclippy::range_plus_one -Wclippy::redundant_closure_for_method_calls -Wclippy::redundant_else -Wclippy::ref_option_ref -Wclippy::return_self_not_must_use -Wclippy::same_functions_in_if_condition -Wclippy::semicolon_if_nothing_returned -Wclippy::single_match_else -Wclippy::stable_sort_primitive -Wclippy::string_add_assign -Wclippy::uninlined_format_args -Wclippy::unnecessary_box_returns -Wclippy::unnecessary_join -Wclippy::unnecessary_wraps -Wclippy::unnested_or_patterns -Wclippy::unreadable_literal -Wclippy::unsafe_derive_deserialize -Wclippy::unused_async -Wclippy::unused_self -Wclippy::used_underscore_binding -Wclippy::zero_sized_map_values

example of warnings

warning: unused `self` argument
   --> src/uu/dd/src/parseargs.rs:281:20
    |
281 |     fn parse_bytes(&self, arg: &str, val: &str) -> Result<usize, ParseError> {
    |                    ^^^^^
    |
    = help: consider refactoring to an associated function
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self

warning: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
  --> src/uu/shuf/src/shuf.rs:67:13
   |
67 | /             matches
68 | |                 .get_one::<String>(options::FILE)
69 | |                 .map(|s| s.as_str())
70 | |                 .unwrap_or("-")
   | |_______________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
   = note: requested on the command line with `-W clippy::map-unwrap-or`
help: use `map_or(<a>, <f>)` instead
   |
69 -                 .map(|s| s.as_str())
69 +                 .map_or("-", |s| s.as_str())
   |

warning: redundant else block
   --> src/uu/split/src/split.rs:669:24
    |
669 |                   } else {
    |  ________________________^
670 | |                     // Move the window to look at only the remaining bytes.
671 | |                     buf = &buf[i..];
672 | |
673 | |                     // Remember for the next iteration that we wrote these bytes.
674 | |                     carryover_bytes_written += num_bytes_written;
675 | |                 }
    | |_________________^
    |
    = help: remove the `else` block and move the contents out
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else

warning: used binding `_x` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
  --> src/uu/factor/src/rho.rs:37:38
   |
37 |                 gcd(n.modulus(), max(_x, _y) - min(_x, _y))
   |                                      ^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding

warning: an inclusive range would be more readable
    --> src/uu/cp/src/cp.rs:1547:42
     |
1547 |     let dest_ancestors = &dest_ancestors[1..1 + k];
     |                                          ^^^^^^^^ help: use: `1..=k`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
     = note: requested on the command line with `-W clippy::range-plus-one`

warning: redundant closure
  --> src/uu/cp/src/copydir.rs:97:36
   |
97 |             root_path.parent().map(|p| p.to_path_buf())
   |                                    ^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::path::Path::to_path_buf`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
   = note: requested on the command line with `-W clippy::redundant-closure-for-method-calls`
warning: this function's return value is unnecessary
   --> src/uu/head/src/head.rs:436:1
    |
436 | / fn uu_head(options: &HeadOptions) -> UResult<()> {
437 | |     let mut first = true;
438 | |     for file in &options.files {
439 | |         let res = match (file.as_str(), options.presume_input_pipe) {
...   |
513 | |     Ok(())
514 | | }
    | |_^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
    = note: requested on the command line with `-W clippy::unnecessary-wraps`
help: remove the return type...
    |
436 | fn uu_head(options: &HeadOptions) -> UResult<()> {
    |                                      ~~~~~~~~~~~
help: ...and then remove returned values
    |
513 -     Ok(())
513 +     
    |

https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms: x457
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls: x90
https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else: x49
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else: x35
https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone: x34
https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or: x26
https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding: x18
https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns: x10
https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string: x10
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps: x9
https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_option: x6
https://rust-lang.github.io/rust-clippy/master/index.html#unused_self: x5
https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding: x5
https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied: x5
https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one: x4
https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg: x3
https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if: x3
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns: x2
https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor: x2
https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs: x2
https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal: x1
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_join: x1
https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args: x1
https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool_assign: x1
https://rust-lang.github.io/rust-clippy/master/index.html#match_bool: x1
https://rust-lang.github.io/rust-clippy/master/index.html#manual_next_back: x1
https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert: x1
https://rust-lang.github.io/rust-clippy/master/index.html#explicit_into_iter_loop: x1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions