about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-05-31 21:14:02 +0000
committerbors <bors@rust-lang.org>2017-05-31 21:14:02 +0000
commite0cc22b4bae8007c59fbe58f2c104ecd743d746a (patch)
tree8c4084d31f5b5c2cbc0d4fcf7d32fe9f3f6a932f /src/libcore
parentfd7b44b78e39c71e5049a210a0c84a8931835cc3 (diff)
parent7f286a8e38258402c6e8e564864ac0132fac2004 (diff)
downloadrust-e0cc22b4bae8007c59fbe58f2c104ecd743d746a.tar.gz
rust-e0cc22b4bae8007c59fbe58f2c104ecd743d746a.zip
Auto merge of #42336 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 7 pull requests

- Successful merges: #42126, #42196, #42252, #42277, #42315, #42329, #42330
- Failed merges:
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/convert.rs38
-rw-r--r--src/libcore/iter/iterator.rs3
-rw-r--r--src/libcore/iter/range.rs5
-rw-r--r--src/libcore/iter/traits.rs4
-rw-r--r--src/libcore/mem.rs8
-rw-r--r--src/libcore/tests/iter.rs1
6 files changed, 51 insertions, 8 deletions
diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs
index 21c75ad3395..11a360ff900 100644
--- a/src/libcore/convert.rs
+++ b/src/libcore/convert.rs
@@ -169,6 +169,40 @@ pub trait AsMut<T: ?Sized> {
 /// - [`From<T>`][From]` for U` implies `Into<U> for T`
 /// - [`into`] is reflexive, which means that `Into<T> for T` is implemented
 ///
+/// # Implementing `Into`
+///
+/// There is one exception to implementing `Into`, and it's kind of esoteric.
+/// If the destination type is not part of the current crate, and it uses a
+/// generic variable, then you can't implement `From` directly.  For example,
+/// take this crate:
+///
+/// ```compile_fail
+/// struct Wrapper<T>(Vec<T>);
+/// impl<T> From<Wrapper<T>> for Vec<T> {
+///     fn from(w: Wrapper<T>) -> Vec<T> {
+///         w.0
+///     }
+/// }
+/// ```
+///
+/// To fix this, you can implement `Into` directly:
+///
+/// ```
+/// struct Wrapper<T>(Vec<T>);
+/// impl<T> Into<Vec<T>> for Wrapper<T> {
+///     fn into(self) -> Vec<T> {
+///         self.0
+///     }
+/// }
+/// ```
+///
+/// This won't always allow the conversion: for example, `try!` and `?`
+/// always use `From`. However, in most cases, people use `Into` to do the
+/// conversions, and this will allow that.
+///
+/// In almost all cases, you should try to implement `From`, then fall back
+/// to `Into` if `From` can't be implemented.
+///
 /// # Examples
 ///
 /// [`String`] implements `Into<Vec<u8>>`:
@@ -285,9 +319,11 @@ pub trait From<T>: Sized {
 /// Library authors should not directly implement this trait, but should prefer
 /// implementing the [`TryFrom`] trait, which offers greater flexibility and
 /// provides an equivalent `TryInto` implementation for free, thanks to a
-/// blanket implementation in the standard library.
+/// blanket implementation in the standard library. For more information on this,
+/// see the documentation for [`Into`].
 ///
 /// [`TryFrom`]: trait.TryFrom.html
+/// [`Into`]: trait.Into.html
 #[unstable(feature = "try_from", issue = "33417")]
 pub trait TryInto<T>: Sized {
     /// The type returned in the event of a conversion error.
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs
index 77cbdb98c83..85149a0f570 100644
--- a/src/libcore/iter/iterator.rs
+++ b/src/libcore/iter/iterator.rs
@@ -130,9 +130,10 @@ pub trait Iterator {
     ///
     /// ```
     /// // an infinite iterator has no upper bound
+    /// // and the maximum possible lower bound
     /// let iter = 0..;
     ///
-    /// assert_eq!((0, None), iter.size_hint());
+    /// assert_eq!((usize::max_value(), None), iter.size_hint());
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs
index e02823fd812..c0313333ea9 100644
--- a/src/libcore/iter/range.rs
+++ b/src/libcore/iter/range.rs
@@ -543,6 +543,11 @@ impl<A: Step> Iterator for ops::RangeFrom<A> where
         mem::swap(&mut n, &mut self.start);
         Some(n)
     }
+
+    #[inline]
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        (usize::MAX, None)
+    }
 }
 
 #[unstable(feature = "fused", issue = "35602")]
diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs
index 798dda19928..015cc150dc2 100644
--- a/src/libcore/iter/traits.rs
+++ b/src/libcore/iter/traits.rs
@@ -109,7 +109,7 @@ pub trait FromIterator<A>: Sized {
     ///
     /// See the [module-level documentation] for more.
     ///
-    /// [module-level documentation]: trait.FromIterator.html
+    /// [module-level documentation]: index.html
     ///
     /// # Examples
     ///
@@ -219,7 +219,7 @@ pub trait IntoIterator {
     ///
     /// See the [module-level documentation] for more.
     ///
-    /// [module-level documentation]: trait.IntoIterator.html
+    /// [module-level documentation]: index.html
     ///
     /// # Examples
     ///
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index 18428d378e3..d11ad76d65d 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -220,7 +220,7 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
 
 /// Returns the [ABI]-required minimum alignment of a type.
 ///
-/// Every valid address of a value of the type `T` must be a multiple of this number.
+/// Every reference to a value of the type `T` must be a multiple of this number.
 ///
 /// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
 ///
@@ -243,7 +243,7 @@ pub fn min_align_of<T>() -> usize {
 
 /// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
 ///
-/// Every valid address of a value of the type `T` must be a multiple of this number.
+/// Every reference to a value of the type `T` must be a multiple of this number.
 ///
 /// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
 ///
@@ -264,7 +264,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
 
 /// Returns the [ABI]-required minimum alignment of a type.
 ///
-/// Every valid address of a value of the type `T` must be a multiple of this number.
+/// Every reference to a value of the type `T` must be a multiple of this number.
 ///
 /// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
 ///
@@ -285,7 +285,7 @@ pub fn align_of<T>() -> usize {
 
 /// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
 ///
-/// Every valid address of a value of the type `T` must be a multiple of this number.
+/// Every reference to a value of the type `T` must be a multiple of this number.
 ///
 /// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
 ///
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index 4030eaf2b23..44d5936c63e 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -764,6 +764,7 @@ fn test_iterator_size_hint() {
     let v2 = &[10, 11, 12];
     let vi = v.iter();
 
+    assert_eq!((0..).size_hint(), (usize::MAX, None));
     assert_eq!(c.size_hint(), (usize::MAX, None));
     assert_eq!(vi.clone().size_hint(), (10, Some(10)));