rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

clippy warnings (rust 1.70) #1677

Open thatmarkenglishguy opened 11 months ago

thatmarkenglishguy commented 11 months ago

Original PR

Test case

git clone git@github.com:rust-bakery/nom.git
cd nom
git checkout 90d78d65a10821272ce8856570605b07a917a6c1
cargo clippy

Build output

warning: unneeded `return` statement
   --> src/multi/mod.rs:817:9
    |
817 | /         return Err(Err::Error(OM::Error::bind(move || {
818 | |           <F as Parser<I>>::Error::from_error_kind(input, ErrorKind::Many1Count)
819 | |         })))
    | |____________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
    = note: `#[warn(clippy::needless_return)]` on by default
    = help: remove `return`

error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
   --> src/traits.rs:336:28
    |
336 |         E::from_error_kind(self.clone(), e)
    |                            ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
    = note: `#[deny(clippy::clone_double_ref)]` on by default
help: try dereferencing it
    |
336 |         E::from_error_kind(&(*self).clone(), e)
    |                            ~~~~~~~~~~~~~~~~
help: or try being explicit if you are sure, that you want to clone a reference
    |
336 |         E::from_error_kind(<&[u8]>::clone(self), e)
    |                            ~~~~~~~~~~~~~~~~~~~~

error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
   --> src/traits.rs:344:32
    |
344 |             E::from_error_kind(self.clone(), e)
    |                                ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
help: try dereferencing it
    |
344 |             E::from_error_kind(&(*self).clone(), e)
    |                                ~~~~~~~~~~~~~~~~
help: or try being explicit if you are sure, that you want to clone a reference
    |
344 |             E::from_error_kind(<&[u8]>::clone(self), e)
    |                                ~~~~~~~~~~~~~~~~~~~~

error: using `clone` on a double-reference; this will copy the reference of type `&str` instead of cloning the inner type
   --> src/traits.rs:533:28
    |
533 |         E::from_error_kind(self.clone(), e)
    |                            ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
help: try dereferencing it
    |
533 |         E::from_error_kind(&(*self).clone(), e)
    |                            ~~~~~~~~~~~~~~~~
help: or try being explicit if you are sure, that you want to clone a reference
    |
533 |         E::from_error_kind(<&str>::clone(self), e)
    |                            ~~~~~~~~~~~~~~~~~~~

warning: length comparison to zero
   --> src/traits.rs:545:19
    |
545 |         } else if self.len() == 0 {
    |                   ^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `self.is_empty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
    = note: `#[warn(clippy::len_zero)]` on by default

error: using `clone` on a double-reference; this will copy the reference of type `&str` instead of cloning the inner type
   --> src/traits.rs:547:32
    |
547 |             E::from_error_kind(self.clone(), e)
    |                                ^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
help: try dereferencing it
    |
547 |             E::from_error_kind(&(*self).clone(), e)
    |                                ~~~~~~~~~~~~~~~~
help: or try being explicit if you are sure, that you want to clone a reference
    |
547 |             E::from_error_kind(<&str>::clone(self), e)
    |                                ~~~~~~~~~~~~~~~~~~~

warning: deref which would be done by auto-deref
   --> src/traits.rs:672:5
    |
672 |     *self
    |     ^^^^^ help: try this: `self`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
    = note: `#[warn(clippy::explicit_auto_deref)]` on by default

warning: this boolean expression can be simplified
    --> src/traits.rs:1457:5
     |
1457 |     !(self.start < self.end)
     |     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.start >= self.end`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
     = note: `#[warn(clippy::nonminimal_bool)]` on by default

error: this range is empty so it will yield no values
    --> src/traits.rs:1462:7
     |
1462 |       1..0
     |       ^^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
     = note: `#[deny(clippy::reversed_empty_ranges)]` on by default
help: consider using the following if you are attempting to iterate over this range in reverse
     |
1462 |       (0..1).rev()
     |

error: this range is empty so it will yield no values
    --> src/traits.rs:1470:7
     |
1470 |       1..0
     |       ^^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
help: consider using the following if you are attempting to iterate over this range in reverse
     |
1470 |       (0..1).rev()
     |

error: this range is empty so it will yield no values
    --> src/traits.rs:1545:7
     |
1545 |       1..0
     |       ^^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
help: consider using the following if you are attempting to iterate over this range in reverse
     |
1545 |       (0..1).rev()
     |

error: this range is empty so it will yield no values
    --> src/traits.rs:1553:7
     |
1553 |       1..0
     |       ^^^^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
help: consider using the following if you are attempting to iterate over this range in reverse
     |
1553 |       (0..1).rev()
     |

warning: redundant clone
   --> src/bytes/mod.rs:958:18
    |
958 |     let i = input.clone();
    |                  ^^^^^^^^ help: remove this
    |
note: cloned value is neither consumed nor mutated
   --> src/bytes/mod.rs:958:13
    |
958 |     let i = input.clone();
    |             ^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
    = note: `#[warn(clippy::redundant_clone)]` on by default

warning: `nom` (lib) generated 5 warnings
error: could not compile `nom` (lib) due to 8 previous errors; 5 warnings emitted

Update 13/09/2023

More warnings generated by merging updated main branch and running:

cargo clippy --all-targets