Change:
I tried printing all valid s by doing and was surprised to find it only printed up to 254. I'm unsure if this is supposed to be this way ( can be used). If so, I'd propose adding this to the Iterators/Ranges section of the book.
The problem is the next method of RangeFrom: It returns the previous value, then updates itself to store the next one. The value 255 ends up being the value that represents a "done" state, so it can't return it. I can't think of any solution that doesn't involve adding a flag to RangeFrom.
Or impl IntoIter instead of Iterator (and use a helper struct to keep track of the range).
Seems similar to .
Question: What is the origin of this Rust behavior, or what is its justification? e.g.: Why an exclusive upper bound on ranges? This caught me by total surprise, coming from Haskell, and I don't know if any Rust I've written for my own cases is wrong now. It behaves differently from similar syntax in Haskell, Swift, and Go, so I'm wondering if it's fruitful to have behavior different from peer languages (in trying to attract people away from languages where syntax like this does not exist.)
Ruby has both exclusive and inclusive ranges
The origin is related to the for-loop idiom in C. corresponds to the range. It has some nice properties such as how it iterates over exactly elements, whereas an inclusive range does and would require you to say, for example, for the indices of a vector if were inclusive. Essentially, it seems like the exclusive behaviour is useful more often than inclusive in a systems language.
Exclusive behaviour is also a leaner implementation. For inclusive behaviour you need some kind of flag for "now yield the inclusive element". This issue is an exact example of why: How do you statefully write an iterator from to , inclusive?
cc , which adjusts this behavior by triggering an overflow on non-wrapped-arithmetic types; it makes the semantics equivalent to repeatedly updating .
so just to be clear, with the above PR merged, now panics. Is this the intended behavior?

Discussion:
use clone::Clone; use cmp; <del> use cmp::Ord; </del> <ins> use cmp::{Ord, PartialOrd, PartialEq}; </ins> use default::Default; use marker; use mem;

/// two `Step` objects. #[unstable(feature = "step_trait", reason = "likely to be replaced by finer-grained traits")] <del> pub trait Step: Ord { </del> <ins> pub trait Step: PartialOrd { </ins> /// Steps `self` if possible. fn step(&self, by: &Self) -> Option<Self>;

#[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] <del> impl<A: Step + One + Clone> Iterator for RangeInclusive<A> { </del> <ins> impl<A> Iterator for RangeInclusive<A> where A: PartialEq + Step + One + Clone, for<'a> &'a A: Add<&'a A, Output = A> { </ins> type Item = A; #[inline]

#[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] <del> impl<A> DoubleEndedIterator for RangeInclusive<A> where A: Step + One + Clone, for<'a> &'a A: Sub<Output=A> </del> <ins> impl<A> DoubleEndedIterator for RangeInclusive<A> where A: PartialEq + Step + One + Clone, for<'a> &'a A: Add<&'a A, Output = A>, for<'a> &'a A: Sub<Output=A> </ins> { #[inline] fn next_back(&mut self) -> Option<A> {

#[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] <del> impl<A: Step + One + Clone> Iterator for ops::Range<A> { </del> <ins> impl<A: Step + One> Iterator for ops::Range<A> where for<'a> &'a A: Add<&'a A, Output = A> { </ins> type Item = A; #[inline] fn next(&mut self) -> Option<A> { if self.start < self.end { <del> match self.start.step(&A::one()) { Some(mut n) => { mem::swap(&mut n, &mut self.start); Some(n) }, None => { let mut n = self.end.clone(); mem::swap(&mut n, &mut self.start); Some(n) } } </del> <ins> let mut n = &self.start + &A::one(); mem::swap(&mut n, &mut self.start); Some(n) </ins> } else { None }

#[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] impl<A: Step + One + Clone> DoubleEndedIterator for ops::Range<A> where <ins> for<'a> &'a A: Add<&'a A, Output = A>, </ins> for<'a> &'a A: Sub<&'a A, Output = A> { #[inline]

#[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] <del> impl<A: Step + One> Iterator for ops::RangeFrom<A> { </del> <ins> impl<A: Step + One> Iterator for ops::RangeFrom<A> where for<'a> &'a A: Add<&'a A, Output = A> { </ins> type Item = A; #[inline] fn next(&mut self) -> Option<A> { <del> self.start.step(&A::one()).map(|mut n| { mem::swap(&mut n, &mut self.start); n }) </del> <ins> let mut n = &self.start + &A::one(); mem::swap(&mut n, &mut self.start); Some(n) </ins> } }

for i in false..true {} //~^ ERROR the trait //~^^ ERROR the trait <ins> //~^^^ ERROR the trait </ins> // Unsized type. let arr: &[_] = &[1, 2, 3];