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

x..(y+1) reads better as x...y #329

Closed
llogiq opened this issue Sep 13, 2015 · 8 comments
Closed

x..(y+1) reads better as x...y #329

llogiq opened this issue Sep 13, 2015 · 8 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-AST Type: Requires working with the AST

Comments

@llogiq
Copy link
Contributor

llogiq commented Sep 13, 2015

Once we have inclusive ranges (which won't be too long; the RFC has recently been accepted), I think we should advise people to use them.

Perhaps we could also check for x...(y-1) while we're at it.

@llogiq llogiq added good-first-issue These issues are a good way to get started with Clippy T-AST Type: Requires working with the AST A-lint Area: New lints labels Sep 14, 2015
@llogiq
Copy link
Contributor Author

llogiq commented Sep 19, 2015

We will have to wait on rust #28237 implementation.

@frewsxcv
Copy link
Member

Similarly, x...(y-1) reads better as x..y

@Stebalien
Copy link

@frewsxcv You have to be careful with that; it only applies to integers. 0.0...(y-1.0) is not 0.0..y

@llogiq
Copy link
Contributor Author

llogiq commented Oct 27, 2015

I have yet to see ranges over anything else but integers, so we may just bail on floats.

OTOH I'm curious: What's the difference between 0.0...(y-1.0) and (0.0..y)?

@Stebalien
Copy link

The latter includes everything but y (e.g. y-0.00000000000000000000000001).

@frewsxcv
Copy link
Member

I'm curious about the justification for making the Range operator work on floating point numbers...

@Manishearth
Copy link
Member

So basically there are two things here, the Range struct and the Range iterator. They're implemented as the same, but as a struct it's useful for specifying ranges, and as an iterator it's ... an iterator.

As far as iterators go there is no difference in the floating point thing. This will be true for most practical uses.

As far as range-as-data goes, of course there is a difference, since it's now a set. However range-as-data doesn't seem to be a common pattern.

@llogiq
Copy link
Contributor Author

llogiq commented Oct 27, 2015

However range-as-data doesn't seem to be a common pattern.

I suspect this will change once someone implements a range set.

niklasf added a commit to niklasf/rust-clippy that referenced this issue Oct 7, 2017
niklasf added a commit to niklasf/rust-clippy that referenced this issue Oct 7, 2017
niklasf added a commit to niklasf/rust-clippy that referenced this issue Oct 7, 2017
@oli-obk oli-obk closed this as completed in d8e0123 Oct 8, 2017
oli-obk added a commit that referenced this issue Oct 8, 2017
Lint range_plus_one and range_minus_one (closes #329)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-AST Type: Requires working with the AST
Projects
None yet
Development

No branches or pull requests

4 participants