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

coord: ranged1d: fix irrefutable if let warning #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

10ne1
Copy link
Contributor

@10ne1 10ne1 commented Dec 21, 2024

I keep getting this annoying warning with rust 1.83:

warning: irrefutable if let pattern
--> plotters/src/coord/ranged1d/types/numeric.rs:29:20
|
29 | if let Ok(index) = Self::ValueType::try_from(index) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
365 | impl_discrete_trait!(RangedCoordusize);
| -------------------------------------- in this macro invocation
|
= note: this pattern will always match, so the if let is useless
= help: consider replacing the if let with a let
= note: #[warn(irrefutable_let_patterns)] on by default
= note: this warning originates in the macro impl_discrete_trait (in Nightly builds, run with -Z macro-backtrace for more info)

This is because the conversion of usize to ValueType always passes, so we don't need the try_from().

The problem with this operation is not the conversion which always succeeds, instead it is the potential overflows, so we use checked_add() which returns None if the addition fails.

I keep getting this annoying warning with rust 1.83:

warning: irrefutable `if let` pattern
   --> plotters/src/coord/ranged1d/types/numeric.rs:29:20
    |
29  |                 if let Ok(index) = Self::ValueType::try_from(index) {
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
365 | impl_discrete_trait!(RangedCoordusize);
    | -------------------------------------- in this macro invocation
    |
    = note: this pattern will always match, so the `if let` is useless
    = help: consider replacing the `if let` with a `let`
    = note: `#[warn(irrefutable_let_patterns)]` on by default
    = note: this warning originates in the macro `impl_discrete_trait` (in Nightly builds, run with -Z macro-backtrace for more info)

This is because the conversion of usize to ValueType always
passes, so we don't need the try_from().

The problem with this operation is not the conversion which
always succeeds, instead it is the potential overflows, so we
use checked_add() which returns None if the addition fails.

Signed-off-by: Adrian Ratiu <[email protected]>
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