From 4f61e160326676cdcce94b9d5bca7d88c5f40ee9 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sun, 8 Feb 2015 00:17:04 +0100 Subject: Fix std::ops::Range size_hint and ExactSizeIterator impls When self.start > self.end, these iterators simply return None, so we adjust the size_hint to just return zero in this case. Certain optimizations can be implemented in and outside libstd if we know we can trust the size_hint for all inputs to for example Range. This corrects the ExactSizeIterator implementations, which IMO were unsound and incorrect previously, since they allowed a range like (2..1) to return a size_hint of -1us in when debug assertions are turned off. --- src/libcore/iter.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f3b42e4f0a5..fa6719a0312 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2646,13 +2646,7 @@ impl Iterator for RangeStepInclusive { macro_rules! range_exact_iter_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl ExactSizeIterator for ::ops::Range<$t> { - #[inline] - fn len(&self) -> usize { - debug_assert!(self.end >= self.start); - (self.end - self.start) as usize - } - } + impl ExactSizeIterator for ::ops::Range<$t> { } )*) } @@ -2673,9 +2667,12 @@ impl Iterator for ::ops::Range { #[inline] fn size_hint(&self) -> (usize, Option) { - debug_assert!(self.end >= self.start); - let hint = (self.end - self.start).to_uint(); - (hint.unwrap_or(0), hint) + if self.start >= self.end { + (0, Some(0)) + } else { + let length = (self.end - self.start).to_uint(); + (length.unwrap_or(0), length) + } } } -- cgit 1.4.1-3-g733a5 From 34afe5e193182a0029abe1ae8258f79f4cd56cd9 Mon Sep 17 00:00:00 2001 From: Alexander Korolkov Date: Thu, 5 Feb 2015 15:04:07 +0300 Subject: Rename Show to Debug, String to Display Update reference.md: - derive() no longer supports Zero trait - derive() now supports Copy trait --- src/doc/reference.md | 4 ++-- src/libcore/any.rs | 2 +- src/libgetopts/lib.rs | 6 +++--- src/librustc/middle/ty.rs | 2 +- src/librustdoc/html/format.rs | 2 +- src/libserialize/json.rs | 4 ++-- src/libstd/old_path/mod.rs | 4 ++-- src/libstd/sys/windows/os.rs | 2 +- src/libsyntax/ast.rs | 1 - 9 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/libcore') diff --git a/src/doc/reference.md b/src/doc/reference.md index 9c8191a386d..999cb217f93 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2354,8 +2354,8 @@ Supported traits for `derive` are: * `FromPrimitive`, to create an instance from a numeric primitive. * `Hash`, to iterate over the bytes in a data type. * `Rand`, to create a random instance of a data type. -* `Show`, to format a value using the `{}` formatter. -* `Zero`, to create a zero instance of a numeric data type. +* `Debug`, to format a value using the `{:?}` formatter. +* `Copy`, for "Plain Old Data" types which can be copied by simply moving bits. ### Compiler Features diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 40c2d82bf4b..462b6771b4a 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -27,7 +27,7 @@ //! # Examples //! //! Consider a situation where we want to log out a value passed to a function. -//! We know the value we're working on implements Show, but we don't know its +//! We know the value we're working on implements Debug, but we don't know its //! concrete type. We want to give special treatment to certain types: in this //! case printing out the length of String values prior to their value. //! We don't know the concrete type of our value at compile time, so we need to diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 1b30bdf230e..72832cb9466 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -195,7 +195,7 @@ pub struct Matches { } /// The type returned when the command line does not conform to the -/// expected format. Use the `Show` implementation to output detailed +/// expected format. Use the `Debug` implementation to output detailed /// information. #[derive(Clone, PartialEq, Eq, Debug)] pub enum Fail { @@ -545,7 +545,7 @@ impl Fail { /// Convert a `Fail` enum into an error string. #[unstable(feature = "rustc_private")] #[deprecated(since = "1.0.0", - reason = "use `fmt::String` (`{}` format specifier)")] + reason = "use `fmt::Display` (`{}` format specifier)")] pub fn to_err_msg(self) -> String { self.to_string() } @@ -579,7 +579,7 @@ impl fmt::Display for Fail { /// `opt_str`, etc. to interrogate results. /// # Panics /// -/// Returns `Err(Fail)` on failure: use the `Show` implementation of `Fail` to display +/// Returns `Err(Fail)` on failure: use the `Debug` implementation of `Fail` to display /// information about it. pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { let opts: Vec = optgrps.iter().map(|x| x.long_to_short()).collect(); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b29a23924bb..034dbb4271d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -70,7 +70,7 @@ use arena::TypedArena; use std::borrow::{BorrowFrom, Cow}; use std::cell::{Cell, RefCell}; use std::cmp; -use std::fmt::{self, Show}; +use std::fmt; use std::hash::{Hash, Writer, SipHasher, Hasher}; use std::mem; use std::ops; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index cc2cf21095e..e916b63eb8d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -10,7 +10,7 @@ //! HTML formatting module //! -//! This module contains a large number of `fmt::String` implementations for +//! This module contains a large number of `fmt::Display` implementations for //! various types in `rustdoc::clean`. These implementations all currently //! assume that HTML output is desired, although it may be possible to redesign //! them in the future to instead emit any format desired. diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index b8383577987..daa358647d8 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1032,7 +1032,7 @@ pub fn as_pretty_json(t: &T) -> AsPrettyJson { impl Json { /// Borrow this json object as a pretty object to generate a pretty - /// representation for it via `Show`. + /// representation for it via `Display`. pub fn pretty(&self) -> PrettyJson { PrettyJson { inner: self } } @@ -3540,7 +3540,7 @@ mod tests { fn test_hashmap_with_enum_key() { use std::collections::HashMap; use json; - #[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Show)] + #[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)] enum Enum { Foo, #[allow(dead_code)] diff --git a/src/libstd/old_path/mod.rs b/src/libstd/old_path/mod.rs index 0d80258d7e0..17cfe1c8297 100644 --- a/src/libstd/old_path/mod.rs +++ b/src/libstd/old_path/mod.rs @@ -228,7 +228,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` fn into_vec(self) -> Vec; - /// Returns an object that implements `Show` for printing paths + /// Returns an object that implements `Display` for printing paths /// /// # Example /// @@ -244,7 +244,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { Display{ path: self, filename: false } } - /// Returns an object that implements `Show` for printing filenames + /// Returns an object that implements `Display` for printing filenames /// /// If there is no filename, nothing will be printed. /// diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index d8e3e6981df..7e684c52341 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -191,7 +191,7 @@ impl<'a> Iterator for SplitPaths<'a> { } } -#[derive(Show)] +#[derive(Debug)] pub struct JoinPathsError; pub fn join_paths(paths: I) -> Result diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 71259ff5d9a..5ec87eaf8d1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -64,7 +64,6 @@ use parse::token; use ptr::P; use std::fmt; -use std::fmt::Show; use std::num::Int; use std::rc::Rc; use serialize::{Encodable, Decodable, Encoder, Decoder}; -- cgit 1.4.1-3-g733a5 From 97a9507232a714b8c9a4341901002f0b761210db Mon Sep 17 00:00:00 2001 From: Michael Budde Date: Mon, 9 Feb 2015 12:56:24 +0100 Subject: Fix links to module-level documentation in `std::cell` Replace links to `../index.html` with `index.html` as they are linking to the `std` module and not `std::cell` as intended. --- src/libcore/cell.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index c82d8c531d2..050b34508ff 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -151,7 +151,7 @@ use option::Option::{None, Some}; /// A mutable memory location that admits only `Copy` data. /// -/// See the [module-level documentation](../index.html) for more. +/// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct Cell { value: UnsafeCell, @@ -259,7 +259,7 @@ impl PartialEq for Cell { /// A mutable memory location with dynamically checked borrow rules /// -/// See the [module-level documentation](../index.html) for more. +/// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct RefCell { value: UnsafeCell, @@ -534,7 +534,7 @@ impl<'b> Clone for BorrowRef<'b> { /// Wraps a borrowed reference to a value in a `RefCell` box. /// A wrapper type for an immutably borrowed value from a `RefCell`. /// -/// See the [module-level documentation](../index.html) for more. +/// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct Ref<'b, T:'b> { // FIXME #12808: strange name to try to avoid interfering with @@ -595,7 +595,7 @@ impl<'b> BorrowRefMut<'b> { /// A wrapper type for a mutably borrowed value from a `RefCell`. /// -/// See the [module-level documentation](../index.html) for more. +/// See the [module-level documentation](index.html) for more. #[stable(feature = "rust1", since = "1.0.0")] pub struct RefMut<'b, T:'b> { // FIXME #12808: strange name to try to avoid interfering with -- cgit 1.4.1-3-g733a5 From 64a4decec779ee0a30585a12352d20a54b722506 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Feb 2015 14:47:09 -0800 Subject: std: Remove typarms from IteratorExt::cloned With associated types an where clauses none of the type parameters are necessary. [breaking-change] --- src/libcore/iter.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 5df64cfaada..fcf46b81a57 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -967,10 +967,9 @@ pub trait IteratorExt: Iterator + Sized { /// Creates an iterator that clones the elements it yields. Useful for converting an /// Iterator<&T> to an Iterator. #[unstable(feature = "core", reason = "recent addition")] - fn cloned(self) -> Cloned where - Self: Iterator, - D: Deref, - T: Clone, + fn cloned(self) -> Cloned where + Self::Item: Deref, + ::Output: Clone, { Cloned { it: self } } -- cgit 1.4.1-3-g733a5 From 605225a366b62f29f5fd4b03cc298fff03bc3bdf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Feb 2015 14:47:55 -0800 Subject: std: Rename IntoIterator::Iter to IntoIter This is in preparation for stabilization of the `IntoIterator` trait. All implementations and references to `Iter` need to be renamed to `IntoIter`. [breaking-change] --- src/libcollections/binary_heap.rs | 4 ++-- src/libcollections/bit.rs | 4 ++-- src/libcollections/btree/map.rs | 6 +++--- src/libcollections/btree/set.rs | 4 ++-- src/libcollections/dlist.rs | 6 +++--- src/libcollections/enum_set.rs | 2 +- src/libcollections/ring_buf.rs | 6 +++--- src/libcollections/vec.rs | 6 +++--- src/libcollections/vec_map.rs | 6 +++--- src/libcore/array.rs | 4 ++-- src/libcore/iter.rs | 6 +++--- src/libcore/slice.rs | 4 ++-- src/libstd/collections/hash/map.rs | 6 +++--- src/libstd/collections/hash/set.rs | 4 ++-- 14 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/libcore') diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 275fc34f813..11576fbb00c 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -656,7 +656,7 @@ impl FromIterator for BinaryHeap { } impl IntoIterator for BinaryHeap { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -664,7 +664,7 @@ impl IntoIterator for BinaryHeap { } impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 8ba0eb9b7ef..6d15a264172 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1071,7 +1071,7 @@ impl<'a> RandomAccessIterator for Iter<'a> { } impl<'a> IntoIterator for &'a Bitv { - type Iter = Iter<'a>; + type IntoIter = Iter<'a>; fn into_iter(self) -> Iter<'a> { self.iter() @@ -1883,7 +1883,7 @@ impl<'a> Iterator for SymmetricDifference<'a> { } impl<'a> IntoIterator for &'a BitvSet { - type Iter = SetIter<'a>; + type IntoIter = SetIter<'a>; fn into_iter(self) -> SetIter<'a> { self.iter() diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index aec50d53808..2cef08725a2 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -463,7 +463,7 @@ impl BTreeMap { } impl IntoIterator for BTreeMap { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -471,7 +471,7 @@ impl IntoIterator for BTreeMap { } impl<'a, K, V> IntoIterator for &'a BTreeMap { - type Iter = Iter<'a, K, V>; + type IntoIter = Iter<'a, K, V>; fn into_iter(self) -> Iter<'a, K, V> { self.iter() @@ -479,7 +479,7 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap { } impl<'a, K, V> IntoIterator for &'a mut BTreeMap { - type Iter = IterMut<'a, K, V>; + type IntoIter = IterMut<'a, K, V>; fn into_iter(mut self) -> IterMut<'a, K, V> { self.iter_mut() diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index c888a261f9d..7cb31ab1f6d 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -481,7 +481,7 @@ impl FromIterator for BTreeSet { } impl IntoIterator for BTreeSet { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -489,7 +489,7 @@ impl IntoIterator for BTreeSet { } impl<'a, T> IntoIterator for &'a BTreeSet { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 748230c5d24..a080146e0ec 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -831,7 +831,7 @@ impl FromIterator for DList { } impl IntoIterator for DList { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -839,7 +839,7 @@ impl IntoIterator for DList { } impl<'a, T> IntoIterator for &'a DList { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -847,7 +847,7 @@ impl<'a, T> IntoIterator for &'a DList { } impl<'a, T> IntoIterator for &'a mut DList { - type Iter = IterMut<'a, T>; + type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { self.iter_mut() diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index da146506077..da533d34703 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -258,7 +258,7 @@ impl FromIterator for EnumSet { } impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { - type Iter = Iter; + type IntoIter = Iter; fn into_iter(self) -> Iter { self.iter() diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 76849e6ade8..5f1dc1d2ef4 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1608,7 +1608,7 @@ impl FromIterator for RingBuf { } impl IntoIterator for RingBuf { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -1616,7 +1616,7 @@ impl IntoIterator for RingBuf { } impl<'a, T> IntoIterator for &'a RingBuf { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -1624,7 +1624,7 @@ impl<'a, T> IntoIterator for &'a RingBuf { } impl<'a, T> IntoIterator for &'a mut RingBuf { - type Iter = IterMut<'a, T>; + type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { self.iter_mut() diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 70097c956cd..1cd2a89ad60 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1388,7 +1388,7 @@ impl FromIterator for Vec { } impl IntoIterator for Vec { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -1396,7 +1396,7 @@ impl IntoIterator for Vec { } impl<'a, T> IntoIterator for &'a Vec { - type Iter = slice::Iter<'a, T>; + type IntoIter = slice::Iter<'a, T>; fn into_iter(self) -> slice::Iter<'a, T> { self.iter() @@ -1404,7 +1404,7 @@ impl<'a, T> IntoIterator for &'a Vec { } impl<'a, T> IntoIterator for &'a mut Vec { - type Iter = slice::IterMut<'a, T>; + type IntoIter = slice::IterMut<'a, T>; fn into_iter(mut self) -> slice::IterMut<'a, T> { self.iter_mut() diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 739b8d8ce19..93d02de9b55 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -669,7 +669,7 @@ impl FromIterator<(usize, V)> for VecMap { } impl IntoIterator for VecMap { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() @@ -677,7 +677,7 @@ impl IntoIterator for VecMap { } impl<'a, T> IntoIterator for &'a VecMap { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -685,7 +685,7 @@ impl<'a, T> IntoIterator for &'a VecMap { } impl<'a, T> IntoIterator for &'a mut VecMap { - type Iter = IterMut<'a, T>; + type IntoIter = IterMut<'a, T>; fn into_iter(mut self) -> IterMut<'a, T> { self.iter_mut() diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 5c4567e567b..a596fe4a588 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -49,7 +49,7 @@ macro_rules! array_impls { } impl<'a, T> IntoIterator for &'a [T; $N] { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -57,7 +57,7 @@ macro_rules! array_impls { } impl<'a, T> IntoIterator for &'a mut [T; $N] { - type Iter = IterMut<'a, T>; + type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { self.iter_mut() diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index fcf46b81a57..2d240a53c4f 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -120,14 +120,14 @@ pub trait FromIterator { /// Conversion into an `Iterator` pub trait IntoIterator { - type Iter: Iterator; + type IntoIter: Iterator; /// Consumes `Self` and returns an iterator over it - fn into_iter(self) -> Self::Iter; + fn into_iter(self) -> Self::IntoIter; } impl IntoIterator for I where I: Iterator { - type Iter = I; + type IntoIter = I; fn into_iter(self) -> I { self diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index fc51920ec6b..459addb09fd 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -628,7 +628,7 @@ impl<'a, T> Default for &'a [T] { // impl<'a, T> IntoIterator for &'a [T] { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -636,7 +636,7 @@ impl<'a, T> IntoIterator for &'a [T] { } impl<'a, T> IntoIterator for &'a mut [T] { - type Iter = IterMut<'a, T>; + type IntoIter = IterMut<'a, T>; fn into_iter(self) -> IterMut<'a, T> { self.iter_mut() diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 710f021d912..18dd122891d 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1377,7 +1377,7 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap S: HashState, H: hash::Hasher { - type Iter = Iter<'a, K, V>; + type IntoIter = Iter<'a, K, V>; fn into_iter(self) -> Iter<'a, K, V> { self.iter() @@ -1389,7 +1389,7 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap S: HashState, H: hash::Hasher { - type Iter = IterMut<'a, K, V>; + type IntoIter = IterMut<'a, K, V>; fn into_iter(mut self) -> IterMut<'a, K, V> { self.iter_mut() @@ -1401,7 +1401,7 @@ impl IntoIterator for HashMap S: HashState, H: hash::Hasher { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index e40f17f29e8..de3c0424c9a 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -840,7 +840,7 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet S: HashState, H: hash::Hasher { - type Iter = Iter<'a, T>; + type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.iter() @@ -852,7 +852,7 @@ impl IntoIterator for HashSet S: HashState, H: hash::Hasher { - type Iter = IntoIter; + type IntoIter = IntoIter; fn into_iter(self) -> IntoIter { self.into_iter() -- cgit 1.4.1-3-g733a5 From 0ee95b917b30d7a48bcafa8b4642f3bcec4d50ff Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Feb 2015 16:24:29 -0800 Subject: std: Mark IntoIterator::into_iter as #[stable Right now it is not possible to write a `for` loop without opting-in to the `core` feature due to the way they're expanding (calling `::std::iter::IntoIterator::into_iter`). There are some planned tweaks to the `IntoIterator` trait (adding an `Item` associated type) which will cause implementations of `IntoIterator` to break, but the *usage* of the trait is currently stable. This commit marks the method `into_iter` as stable as the name will not be changing, nor the fact that it takes no arguments and returns one type (which is determiend by the `Self` type). This means that usage of `for` loops is now stable but manual implementations of the `IntoIterator` trait will continue to be unstable. --- src/libcore/iter.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libcore') diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 2d240a53c4f..20cd1c30839 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -123,6 +123,7 @@ pub trait IntoIterator { type IntoIter: Iterator; /// Consumes `Self` and returns an iterator over it + #[stable(feature = "rust1", since = "1.0.0")] fn into_iter(self) -> Self::IntoIter; } -- cgit 1.4.1-3-g733a5 From e40d05800bd2f6c1e68548246a21f305447ae300 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 9 Feb 2015 21:51:30 -0500 Subject: Remove incorrect docs from mem::transmute Fixes #22032 --- src/libcore/intrinsics.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 125e8a0e814..5562845e11d 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -222,12 +222,11 @@ extern "rust-intrinsic" { /// Unsafely transforms a value of one type into a value of another type. /// - /// Both types must have the same size and alignment, and this guarantee - /// is enforced at compile-time. + /// Both types must have the same size. /// /// # Examples /// - /// ```rust + /// ``` /// use std::mem; /// /// let v: &[u8] = unsafe { mem::transmute("L") }; -- cgit 1.4.1-3-g733a5 From 17abb43248e5b8ce65ede45d7446fa7247eed5ae Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 9 Feb 2015 21:44:11 -0500 Subject: Set up docs for missing core types Fixes #22085 --- src/libcore/lib.rs | 4 ++++ src/libcore/tuple.rs | 1 + 2 files changed, 5 insertions(+) (limited to 'src/libcore') diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index df4942b509b..a122bcb2c7a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -141,6 +141,10 @@ pub mod hash; pub mod fmt; pub mod error; +#[doc(primitive = "bool")] +mod bool { +} + // note: does not need to be public mod tuple; mod array; diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 64c2964eb7c..72b2d5dc188 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -34,6 +34,7 @@ //! * `Default` #![stable(feature = "rust1", since = "1.0.0")] +#![doc(primitive = "tuple")] use clone::Clone; use cmp::*; -- cgit 1.4.1-3-g733a5 From 792dc8d067d1f11e08e859ccdd45d59436773fc9 Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Tue, 10 Feb 2015 14:37:44 +0100 Subject: Made the `ptr::Unique` type accept unsized types, to allow for use cases like sending a raw pointer slice across thread boundaries. --- src/libcore/ptr.rs | 6 +++--- src/libcoretest/ptr.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index ba1eae551ff..bf801a88ca5 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -522,21 +522,21 @@ impl PartialOrd for *mut T { /// Useful for building abstractions like `Vec` or `Box`, which /// internally use raw pointers to manage the memory that they own. #[unstable(feature = "core", reason = "recently added to this module")] -pub struct Unique(pub *mut T); +pub struct Unique(pub *mut T); /// `Unique` pointers are `Send` if `T` is `Send` because the data they /// reference is unaliased. Note that this aliasing invariant is /// unenforced by the type system; the abstraction using the /// `Unique` must enforce it. #[unstable(feature = "core", reason = "recently added to this module")] -unsafe impl Send for Unique { } +unsafe impl Send for Unique { } /// `Unique` pointers are `Sync` if `T` is `Sync` because the data they /// reference is unaliased. Note that this aliasing invariant is /// unenforced by the type system; the abstraction using the /// `Unique` must enforce it. #[unstable(feature = "core", reason = "recently added to this module")] -unsafe impl Sync for Unique { } +unsafe impl Sync for Unique { } impl Unique { /// Returns a null Unique. diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index 7f0b97c53d4..2365b907b3f 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -167,3 +167,12 @@ fn test_set_memory() { unsafe { set_memory(ptr, 5u8, xs.len()); } assert!(xs == [5u8; 20]); } + +#[test] +fn test_unsized_unique() { + let xs: &mut [_] = &mut [1, 2, 3]; + let ptr = Unique(xs as *mut [_]); + let ys = unsafe { &mut *ptr.0 }; + let zs: &mut [_] = &mut [1, 2, 3]; + assert!(ys == zs); +} -- cgit 1.4.1-3-g733a5