]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #15910 : sfackler/rust/nogc, r=cmr
authorbors <bors@rust-lang.org>
Wed, 23 Jul 2014 10:06:09 +0000 (10:06 +0000)
committerbors <bors@rust-lang.org>
Wed, 23 Jul 2014 10:06:09 +0000 (10:06 +0000)
src/doc/guide.md
src/libcore/iter.rs
src/libcore/num/mod.rs

index 9c52e3814624ef100deb62d8a0c2b81945134c63..387841ab3fcefac72c86f748842a915adf86fe75 100644 (file)
@@ -624,15 +624,10 @@ let x = (let y = 5i); // found `let` in ident position
 The compiler is telling us here that it was expecting to see the beginning of
 an expression, and a `let` can only begin a statement, not an expression.
 
-However, assigning to a variable binding is an expression:
-
-```{rust}
-let x;
-let y = x = 5i;
-```
-
-In this case, we have an assignment expression (`x = 5`) whose value is
-being used as part of a `let` declaration statement (`let y = ...`).
+Note that assigning to an already-bound variable (e.g. `y = 5i`) is still an
+expression, although its value is not particularly useful. Unlike C, where an
+assignment evaluates to the assigned value (e.g. `5i` in the previous example),
+in Rust the value of an assignment is the unit type `()` (which we'll cover later).
 
 The second kind of statement in Rust is the **expression statement**. Its
 purpose is to turn any expression into a statement. In practical terms, Rust's
index 6ba0f7c3a157543d3b4968b5476bdbed642ae4d9..7706d01cbaed6bb3ee85d5994fa6359060866142 100644 (file)
@@ -99,9 +99,10 @@ pub trait Iterator<A> {
     /// Advance the iterator and return the next value. Return `None` when the end is reached.
     fn next(&mut self) -> Option<A>;
 
-    /// Return a lower bound and upper bound on the remaining length of the iterator.
+    /// Returns a lower and upper bound on the remaining length of the iterator.
     ///
-    /// The common use case for the estimate is pre-allocating space to store the results.
+    /// An upper bound of `None` means either there is no known upper bound, or the upper bound
+    /// does not fit within a `uint`.
     #[inline]
     fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
 
@@ -644,6 +645,9 @@ fn min_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
 }
 
 /// A range iterator able to yield elements from both ends
+///
+/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
+/// elements from the *same* range, and do not work independently of each other.
 pub trait DoubleEndedIterator<A>: Iterator<A> {
     /// Yield an element from the end of the range, returning `None` if the range is empty.
     fn next_back(&mut self) -> Option<A>;
@@ -690,12 +694,15 @@ fn reverse_(&mut self) {
 /// An object implementing random access indexing by `uint`
 ///
 /// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
+/// Calling `next()` or `next_back()` on a `RandomAccessIterator`
+/// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)`
+/// after `it.next()` is called.
 pub trait RandomAccessIterator<A>: Iterator<A> {
     /// Return the number of indexable elements. At most `std::uint::MAX`
     /// elements are indexable, even if the iterator represents a longer range.
     fn indexable(&self) -> uint;
 
-    /// Return an element at an index
+    /// Return an element at an index, or `None` if the index is out of bounds
     fn idx(&mut self, index: uint) -> Option<A>;
 }
 
index 3ffc1d5e11c7371dfe41667fe788a11900ad2e4b..f0c537efa4656738fc5ece7dcf5ea439e7372c0b 100644 (file)
@@ -75,6 +75,7 @@ pub trait Zero: Add<Self, Self> {
     fn zero() -> Self;
 
     /// Returns `true` if `self` is equal to the additive identity.
+    #[inline]
     fn is_zero(&self) -> bool;
 }
 
@@ -89,23 +90,11 @@ fn is_zero(&self) -> bool { *self == $v }
     }
 )
 
-macro_rules! zero_float_impl(
-    ($t:ty, $v:expr) => {
-        impl Zero for $t {
-            #[inline]
-            fn zero() -> $t { $v }
-
-            #[inline]
-            fn is_zero(&self) -> bool { *self == $v || *self == -$v }
-        }
-    }
-)
-
 zero_impl!(uint, 0u)
-zero_impl!(u8,  0u8)
-zero_impl!(u16, 0u16)
-zero_impl!(u32, 0u32)
-zero_impl!(u64, 0u64)
+zero_impl!(u8,   0u8)
+zero_impl!(u16,  0u16)
+zero_impl!(u32,  0u32)
+zero_impl!(u64,  0u64)
 
 zero_impl!(int, 0i)
 zero_impl!(i8,  0i8)
@@ -113,8 +102,8 @@ fn is_zero(&self) -> bool { *self == $v || *self == -$v }
 zero_impl!(i32, 0i32)
 zero_impl!(i64, 0i64)
 
-zero_float_impl!(f32, 0.0f32)
-zero_float_impl!(f64, 0.0f64)
+zero_impl!(f32, 0.0f32)
+zero_impl!(f64, 0.0f64)
 
 /// Returns the additive identity, `0`.
 #[inline(always)] pub fn zero<T: Zero>() -> T { Zero::zero() }