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

coord: ranged1d: fix irrefutable if let warning#667

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

10ne1
Copy link
Contributor

I keep getting this annoying warning with rust 1.83:

warning: irrefutableif 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 theif let is useless
= help: consider replacing theif let with alet
= note:#[warn(irrefutable_let_patterns)] on by default
= note: this warning originates in the macroimpl_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.

nielsle reacted with heart emoji
@booti386
Copy link
Contributor

Thanks for your PR.
However, i will complete your analysis. The macroimpl_discrete_trait that you patched is used several times at the bottom of the file, to implementDiscreteRanged for all the differentRangedCoord* types.
The specific call that produces the warning that you're citing isimpl_discrete_trait!(RangedCoordusize);, because we convert usize to usize, which always succeed. However it is not always true for the other calls, e.g.impl_discrete_trait!(RangedCoordu32); when usize is bigger than u32 on the target architecture.
So I suggest you modify your patch slightly (and don't bother adding me as a co-author, I don't care):

fnfrom_index(&self,index:usize) ->Option<Self::ValueType>{Self::ValueType::try_from(index).ok().and_then(|index|self.0.checked_add(index))}

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>
@10ne110ne1force-pushed thedev/aratiu/fix-irrefutable-let-warn branch from43990c4 todd806bdCompareMarch 14, 2025 11:39
@10ne1
Copy link
ContributorAuthor

Thanks@booti386 I've updated the PR with your suggestion.

@AaronErhardt Can we please land this? It's been waiting for some while now. The failing checks seem to be unrelated.

booti386 reacted with heart emoji

Copy link
Member

@AaronErhardtAaronErhardt left a comment

Choose a reason for hiding this comment

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

Thanks!

nielsle and 10ne1 reacted with heart emoji
@AaronErhardtAaronErhardt merged commit0f195ea intoplotters-rs:masterMar 27, 2025
8 of 18 checks passed
@10ne110ne1 deleted the dev/aratiu/fix-irrefutable-let-warn branchApril 12, 2025 07:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AaronErhardtAaronErhardtAaronErhardt approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@10ne1@booti386@AaronErhardt

[8]ページ先頭

©2009-2025 Movatter.jp