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

Reversed empty ranges #5583

Merged
merged 4 commits into from
May 14, 2020
Merged

Reversed empty ranges #5583

merged 4 commits into from
May 14, 2020

Conversation

ebroto
Copy link
Member

@ebroto ebroto commented May 10, 2020

This lint checks range expressions with inverted limits which result in empty ranges. This includes also the ranges used to index slices.

The lint reverse_range_loop was covering iteration of reversed ranges in a for loop, which is a subset of what this new lint covers, so it has been removed. I'm not sure if that's the best choice. It would be doable to check in the new lint that we are not in the arguments of a for loop; I went for removing it because the logic was too similar to keep them separated.

changelog: Added reversed_empty_ranges lint that checks for ranges where the limits have been inverted, resulting in empty ranges. Removed reverse_range_loop which was covering a subset of the new lint.

Closes #4192
Closes #96

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Just a quick comment, since I just skimmed the changes: Please move the tests instead of removing them. You can move them in a separate file, like reversed_empty_ranges_loops.rs.

I'm good with merging these two lints though. 👍

@flip1995 flip1995 requested a review from yaahc May 11, 2020 18:02
Copy link
Member

@yaahc yaahc left a comment

Choose a reason for hiding this comment

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

Looks good to me.

I am worried about people who have set the old lint to deny who will find that reversed loop ranges can now sneak back into their code, but I figure that most people are not going to be denying this specific lint directly, so we don't actually have a problem in practice.

@flip1995 flip1995 added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label May 11, 2020
@flip1995
Copy link
Member

@yaahc I don't think this will be an issue, since the message "this lint is now included in reversed_empty_ranges" will be displayed to the user. no regressions should come from this, that's why we should persist the tests.

@yaahc
Copy link
Member

yaahc commented May 11, 2020

got it, okay, sounds perfect to me then.

}

for i in (10..0).map(|x| x * 2) {
// not an error, it can't be known what arbitrary methods do to a range
Copy link
Member Author

@ebroto ebroto May 11, 2020

Choose a reason for hiding this comment

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

This will trigger the lint now. Although the mapped closure will never run in this case (nor other Iterator methods), it makes me think that someone could e.g. implement a trait for Range that manipulates the bounds arbitrarily (fields are pub)...

The fact that the range is empty will not change though, and seems a niche case. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed 👍

@flip1995 flip1995 added S-waiting-on-bors Status: The marked PR was approved and is only waiting bors and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 12, 2020
@flip1995
Copy link
Member

Thanks, waiting for rustup #5587

@flip1995
Copy link
Member

Needs a rebase

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-bors Status: The marked PR was approved and is only waiting bors labels May 13, 2020
@flip1995
Copy link
Member

Thanks!

@bors r=yaahc,flip1995

@bors
Copy link
Collaborator

bors commented May 14, 2020

📌 Commit 671c1e3 has been approved by yaahc,flip1995

@bors
Copy link
Collaborator

bors commented May 14, 2020

⌛ Testing commit 671c1e3 with merge e1842b0...

@bors
Copy link
Collaborator

bors commented May 14, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: yaahc,flip1995
Pushing e1842b0 to master...

@bors bors merged commit e1842b0 into rust-lang:master May 14, 2020
@ebroto ebroto deleted the reversed_empty_ranges branch May 15, 2020 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
4 participants