-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement range syntax #19858
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
Implement range syntax #19858
Conversation
Yay! Delighted to see this, @nick29581 |
#[lang="full_range"] | ||
pub struct FullRange; | ||
|
||
/// A range which i bounded at both ends. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is". Might want to mention "half open" in the type docs as well.
@nick29581 left some comments -- though possibly on a stale commit? In any case, I'm basically fine with landing this as-is in terms of naming and placement of the |
@aturon I like the |
@nick29581 What about making it return |
@aturon it is for now, yes (if the trait is meant to be more generally useful, then I guess it should handle more here, but perhaps we should ere on the side of YAGNI here.). Does size_hint need to be fast? I.e., is it worth trying to avoid the branch? If not, then Option seems fine for now. |
Usually I also agree that YAGNI seems best here. We recently axed a lot of the On Mon, Dec 15, 2014 at 3:48 PM, Nick Cameron [email protected]
|
Is something like the following in this PR? Just a thought I had a few minutes ago.
|
@sinistersnare yes, that will work, you don't even need the brackets around the range |
Exciting. |
So this looks reasonable, though I'm wondering if we can just desugar these expressions in the front-end and save ourselves a lot of weird bugs down the line. This seems like a classic case. |
r+ modulo comments and in particular the question about using a common supertype, though perhaps we can discuss whether to desugar etc on IRC |
/// Change self to the previous object. | ||
fn step_back(&mut self); | ||
/// The steps_between two step objects. | ||
/// a should always be less than b, so the result should never be negtive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/negtive/negative/
Closes #19794 r? @aturon for the first patch r? @nikomatsakis for the rest
The first six commits are from an earlier PR (#19858) and have already been reviewed. This PR makes an awful hack in the compiler to accommodate slices both natively and in the index a range form. After a snapshot we can hopefully add the new Index impls and then we can remove these awful hacks. r? @nikomatsakis (or anyone who knows the compiler, really)
The first six commits are from an earlier PR (rust-lang#19858) and have already been reviewed. This PR makes an awful hack in the compiler to accommodate slices both natively and in the index a range form. After a snapshot we can hopefully add the new Index impls and then we can remove these awful hacks. r? @nikomatsakis (or anyone who knows the compiler, really)
Closes #19794
r? @aturon for the first patch
r? @nikomatsakis for the rest