Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd806bd

Browse files
committed
coord: ranged1d: fix irrefutable if let warning
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 alwayspasses, so we don't need the try_from() in all cases.An additional problem are potential overflows so we usechecked_add() which returns None if the addition fails,thus also avoiding the irrefutable let pattern while alsoprotecting against overflows.Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
1 parent3ad52da commitdd806bd

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

‎plotters/src/coord/ranged1d/types/numeric.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ macro_rules! impl_discrete_trait {
2626
}
2727

2828
fn from_index(&self, index:usize) ->Option<Self::ValueType>{
29-
ifletOk(index) =Self::ValueType::try_from(index){
30-
returnSome(self.0 + index);
31-
}
32-
None
29+
Self::ValueType::try_from(index)
30+
.ok()
31+
.and_then(|index|self.0.checked_add(index))
3332
}
3433
}
3534
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp