coord: ranged1d: fix irrefutable if let warning #667
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
I keep getting this annoying warning with rust 1.83:
warning: irrefutable
if letpattern--> 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 letis useless= help: consider replacing the
if letwith alet= 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.