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 several clippy lints #70

Merged
merged 7 commits into from
Nov 20, 2021
Merged

Fix several clippy lints #70

merged 7 commits into from
Nov 20, 2021

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Oct 15, 2021

This branch contains a number of small fixes for several clippy lints:

  • 00f5715 Add Slice::is_empty() method

    Clippy lints about types which have a public len method but no
    corresponding is_empty method. Therefore, I've added an is_empty
    method that returns true if self.len() > 0.

    Since this is a new API that we'll have to support, it would also be
    fine to solve this by not adding the method and just suppressing the
    warning...but it seems worth having for consistency with the
    underlying slice's methods? And, I don't see how this could really
    pose a forward-compatibility hazard, since Slice is...always going
    to be backed by an actual slice...

  • fb8c985 don't call clone on Value, which is Copy

  • dd3018e fix clippy lints about static lifetimes

    Clippy lints on explicitly using the 'static lifetime for values in
    a static, and when passing a reference to a reference that is
    automatically dereferenced (into a single reference) by the compiler.
    This commit fixes those lints.

  • fbc5daa silence clippy warning on approximate values of pi

  • c81f5b9 silence warning on non-epsilon float comparisons

    The tests will make assertions that particular values are recorded in
    a particular order. When testing with floating-point values, clippy
    emits a warning that we should be using epsilon comparisons rather
    than bit equality. However, this isn't an issue here, since the tests
    just using float literals, and if the right float is recorded in the
    right order, they will be precisely equal.

  • 0e12f69 Fix clippy::drop_ref lint

    Clippy doesn't like calls to std::mem::drop with references ---
    since the pointed value is not actually dropped. In this case, this
    is the correct behavior, but clippy views this as a footgun if the
    user means to actually drop the value behind the reference.

    Here, we're using drop to ignore values in no-op default impls for
    trait methods. I've changed those methods to use let _ to ignore
    parameters instead. This doesn't trigger the clippy lint and is maybe
    more idiomatic anyway.

hawkw added 5 commits October 15, 2021 10:33
Clippy doesn't like calls to `std::mem::drop` with references --- since
the pointed value is not actually dropped. In this case, this *is* the
correct behavior, but clippy views this as a footgun if the user means
to actually drop the value behind the reference.

Here, we're using `drop` to ignore values in no-op default impls
for trait methods.  I've
changed those methods to use `let _` to ignore parameters instead. This
doesn't trigger the clippy lint and is maybe more idiomatic anyway.

Signed-off-by: Eliza Weisman <[email protected]>
The tests will make assertions that particular values are recorded in a
particular order. When testing with floating-point values, clippy emits
a warning that we should be using epsilon comparisons rather than
bit equality. However, this isn't an issue here, since the tests just using
float literals, and if the right float is recorded in the right order,
they will be precisely equal.

Signed-off-by: Eliza Weisman <[email protected]>
Clippy lints on explicitly using the `'static` lifetime for values in a
static, and when passing a reference to a reference that is
automatically dereferenced (into a single reference) by the compiler.
This commit fixes those lints.

Signed-off-by: Eliza Weisman <[email protected]>
This fixes a clippy lint.

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw requested review from carllerche and taiki-e October 15, 2021 19:34
Clippy lints about types which have a public `len` method but no
corresponding `is_empty` method. Therefore, I've added an `is_empty`
method that returns `true` if `self.len() > 0`.

Since this is a new API that we'll have to support, it would also be
fine to solve this by _not_ adding the method and just suppressing the
warning...but it seems worth having for consistency with the underlying
slice's methods? And, I don't see how this could really pose a
forward-compatibility hazard, since `Slice` is...always going to be
backed by an actual slice...
valuable/src/slice.rs Outdated Show resolved Hide resolved
Comment on lines +198 to +206
// When testing floating-point values, the
// actual value will be the exact same float
// value as the expected, if everything is
// working correctly. So, it's not strictly
// necessary to use epsilon comparisons here,
// and modifying the macro to use epsilon
// comparisons for floats would make it
// significantly more complex...
#[allow(clippy::float_cmp)]
Copy link
Member

Choose a reason for hiding this comment

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

Well, float_cmp will soon be allowed by default. rust-lang/rust-clippy#7692

@carllerche carllerche merged commit 997e807 into master Nov 20, 2021
@taiki-e taiki-e deleted the eliza/clippy branch November 21, 2021 05:49
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.

3 participants