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

[manual_range_patterns]: lint negative values #11096

Merged
merged 2 commits into from Jul 10, 2023
Merged

Conversation

y21
Copy link
Member

@y21 y21 commented Jul 3, 2023

Fixes #11091.

Now also lints negative values in patterns (-1 | -2 | -3)

changelog: [manual_range_patterns]: lint negative values

@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2023

r? @giraffate

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 3, 2023
@y21
Copy link
Member Author

y21 commented Jul 3, 2023

Okay, I think this requires some pretty involved changes to handle "large" numbers correctly. For example:

    matches!(
        1u128,
        340282366920938463463374607431768211455
            | 340282366920938463463374607431768211454
            | 340282366920938463463374607431768211453
    );

This currently emits the warning "help: try: -3..=-1", because the integer literal wraps around. This probably needs lots of casting and checks to make all the comparisons etc work. Though maybe there's a nicer way to do this. Will have to think about it.
(or I guess we could also just ignore numbers >i128::MAX for now 🤔 )

@Centri3
Copy link
Member

Centri3 commented Jul 3, 2023

Okay, I think this requires some pretty involved changes to handle "large" numbers correctly. For example:

    matches!(
        1u128,
        340282366920938463463374607431768211455
            | 340282366920938463463374607431768211454
            | 340282366920938463463374607431768211453
    );

This currently emits the warning "help: try: -3..=-1", because the integer literal wraps around. This probably needs lots of casting and checks to make all the comparisons etc work. Though maybe there's a nicer way to do this. Will have to think about it. (or I guess we could also just ignore numbers >i128::MAX for now 🤔 )

The type of the integer is known in LitKind::Int, you can cast it using that (like match int_ty { Isize => val as isize, _ => /* etc */ })

@y21
Copy link
Member Author

y21 commented Jul 3, 2023

yep but what I mean is that, unless I'm overthinking this way too much, the logic will get very complicated very quickly here now that we need these casts and checks basically for every use of min/max (to get additions/less than/greater than/range checks etc. right) and it probably requires very large changes

@Centri3
Copy link
Member

Centri3 commented Jul 3, 2023

That's a good point.

Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

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

(or I guess we could also just ignore numbers >i128::MAX for now 🤔 )

IMO it would be better to ignore these numbers or just note it in Known problems section.

@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Jul 10, 2023

📌 Commit c927912 has been approved by giraffate

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jul 10, 2023

⌛ Testing commit c927912 with merge 9058b04...

@bors
Copy link
Collaborator

bors commented Jul 10, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: giraffate
Pushing 9058b04 to master...

@bors bors merged commit 9058b04 into rust-lang:master Jul 10, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FN manual_range_patterns : negative values
5 participants