Uh oh!
There was an error while loading. Please reload this page.
explicitly show how iterating over .. fails - #35701
Conversation
I've also removed the `main()` wrapper, which I believe is extraneous. LMK if that's incorrect.
matthew-piziak
commented
Aug 15, 2016
rust-highfive
commented
Aug 15, 2016
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
strega-nil
commented
Aug 15, 2016
It's technically an |
matthew-piziak
commented
Aug 16, 2016
@ubsan I thought that too, but the error threw me off. |
strega-nil
commented
Aug 16, 2016
@matthew-piziak weird implementation thing. It's looking for IntoIter through Iterator |
matthew-piziak
commented
Aug 16, 2016
@ubsan Could you elaborate on that? I think I'm missing a piece of the puzzle. I know that |
strega-nil
commented
Aug 16, 2016
@matthew-piziak Okay, so. for x in y {
...}becomes let __tmp = IntoIterator::into_iter(y);whileletSome(x) = __tmp.next(){
...}the only thing that is necessarily an However, the question is, how does Sorry if this is confusing, I'm pretty tired. |
matthew-piziak
commented
Aug 16, 2016
Not at all. Thank you so much for the explanation. I get how it works now. :) |
Saying that "[for-loop iteration] fails because .. has no IntoIterator impl" is more direct than saying "...no Iterator impl" because for loops sugar into IntoIterator invocations. It just happens that the other Range* operators implement Iterator and rely on the fact that `IntoIterator` is implemented for `T: Iterator`.
| /// assert_eq!(arr[1..3], [ 1,2 ]); | ||
| /// } | ||
| /// // for i in .. { | ||
| /// // println!("This errors because .. has no IntoIterator impl"); |
There was a problem hiding this comment.
So, usually rather than commenting the code out, we put things in its own example marked with ignore. And in general, these feel like three separate examples to me. Could you maybe split them up, and put a little sentence between them explaining it?
So for example:
/// The `..` syntax is a `RangeFull`:
///
/// ```
/// assert_eq!((..), std::ops::RangeFull);
/// ```
///
/// It does not have an `IntoIterator` implementation, so you can't use it in a
/// `for` loop directly. This won't compile:
///
/// ```ignore
/// for i in .. {
/// // ...
/// }
/// ```
Something like that? What do you think?
There was a problem hiding this comment.
Yes! I'm thinking that's much better. Will impl. :)
steveklabnik
commented
Aug 19, 2016
@bors: r+ rollup |
bors
commented
Aug 19, 2016
📌 Commit 469b7fd has been approved by |
…ror, r=steveklabnik explicitly show how iterating over `..` fails I've also removed the `main()` wrapper, which I believe is extraneous. LMK if that's incorrect.
…ror, r=steveklabnik explicitly show how iterating over `..` fails I've also removed the `main()` wrapper, which I believe is extraneous. LMK if that's incorrect.
…ror, r=steveklabnik explicitly show how iterating over `..` fails I've also removed the `main()` wrapper, which I believe is extraneous. LMK if that's incorrect.
Feedback on PR rust-lang#35701 seems to be positive, so this does the same thing for `RangeTo` and `RangeToInclusive`.
…ple-error, r=steveklabnik show how iterating over `RangeTo` and `RangeToInclusive` fails Feedback on PR rust-lang#35701 seems to be positive, so this does the same thing for `RangeTo` and `RangeToInclusive`.
I've also removed the
main()wrapper, which I believe is extraneous.LMK if that's incorrect.