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

Some more cleanup suggested by cargo clippy #402

Merged
merged 11 commits into from
Dec 28, 2020
Merged

Conversation

crawford
Copy link
Contributor

This is a follow-on to #395. I still have some more changes locally, but I can follow up with another pull request once I get them cleaned up a bit.

These were flagged by `cargo clippy`:

    warning: length comparison to zero
These were flagged by `cargo clippy`:

    warning: you seem to be trying to use match for destructuring a
             single pattern. Consider using `if let`

This also silences a few cases where the match couldn't be replaced with
an if because of the following error:

    error: attributes are not yet allowed on `if` expressions

Once we increase the minimum Rust version to 1.43, these can be updated
as well.
These were flagged by `cargo clippy`:

    warning: you don't need to add `&` to all patterns

This should have happened in ac830e8, but I guess I missed it.
src/wire/icmpv6.rs Outdated Show resolved Hide resolved
src/wire/icmpv4.rs Outdated Show resolved Hide resolved
These were flagged by `cargo clippy`:

    warning: this seems like a manual implementation of the
             non-exhaustive pattern

The non_exhaustive attribute isn't available until we increase the
minimum Rust version to 1.40, so we should just silence these warnings
in the meantime.
These were flagged by `cargo clippy`:

    warning: item has a public `len` method but no corresponding
             `is_empty` method
These were flagged by `cargo clippy`:

    warning: match expression looks like `matches!` macro

The matches! macro isn't stabilized until Rust 1.42.
These were flagged by `cargo clippy`:

    warning: manual implementation of an assign operation
These were flagged by `cargo clippy`:

    warning: explicit lifetimes given in parameter types where they
             could be elided (or replaced with `'_` if needed by type
             declaration)
These were flagged by `cargo clippy`:

    warning: calling `subsec_millis()` is more concise than this
             calculation
These were flagged by `cargo clippy`:

    warning: redundant closure found
These were flagged by `cargo clippy`:

    warning: called `is_some()` after searching an `Iterator` with find.
             This is more succinctly expressed by calling `any()`.
    warning: this `.into_iter()` call is equivalent to `.iter_mut()` and
             will not consume the `BTreeMap`
    warning: called `skip_while(p).next()` on an `Iterator`

The skip_while conversion is a little tricky. Clippy notes that:

    warning: called `skip_while(p).next()` on an `Iterator`
    help: this is more succinctly expressed by calling `.find(!p)` instead

So the condition of the skip_while is inverted and then simplified using
De Morgan's laws.
@Dirbaio
Copy link
Member

Dirbaio commented Dec 28, 2020

Very nice! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants