-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
explicitly show how iterating over ..
fails
#35701
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.
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. |
It's technically an |
@ubsan I thought that too, but the error threw me off.
|
@matthew-piziak weird implementation thing. It's looking for IntoIter through Iterator |
@ubsan Could you elaborate on that? I think I'm missing a piece of the puzzle. I know that |
@matthew-piziak Okay, so. for x in y {
...
} becomes let __tmp = IntoIterator::into_iter(y);
while let Some(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. |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I'm thinking that's much better. Will impl. :)
@bors: r+ rollup |
📌 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.