diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 6edee82dc30af..e4bc6a393c491 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -563,6 +563,8 @@ impl BinaryHeap { pub fn is_empty(&self) -> bool { self.len() == 0 } /// Clears the binary heap, returning an iterator over the removed elements. + /// + /// The elements are removed in arbitrary order. #[inline] #[unstable(feature = "collections", reason = "matches collection reform specification, waiting for dust to settle")] diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 2a668b0869d25..688d730e25287 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -13,25 +13,23 @@ //! The `slice` module contains useful code to help work with slice values. //! Slices are a view into a block of memory represented as a pointer and a length. //! -//! ```rust -//! # #![feature(core)] +//! ``` //! // slicing a Vec -//! let vec = vec!(1, 2, 3); -//! let int_slice = vec.as_slice(); +//! let vec = vec![1, 2, 3]; +//! let int_slice = &vec[..]; //! // coercing an array to a slice //! let str_slice: &[&str] = &["one", "two", "three"]; //! ``` //! //! Slices are either mutable or shared. The shared slice type is `&[T]`, -//! while the mutable slice type is `&mut[T]`. For example, you can mutate the -//! block of memory that a mutable slice points to: +//! while the mutable slice type is `&mut [T]`, where `T` represents the element +//! type. For example, you can mutate the block of memory that a mutable slice +//! points to: //! -//! ```rust -//! let x: &mut[i32] = &mut [1, 2, 3]; +//! ``` +//! let x = &mut [1, 2, 3]; //! x[1] = 7; -//! assert_eq!(x[0], 1); -//! assert_eq!(x[1], 7); -//! assert_eq!(x[2], 3); +//! assert_eq!(x, &[1, 7, 3]); //! ``` //! //! Here are some of the things this module contains: @@ -41,49 +39,43 @@ //! There are several structs that are useful for slices, such as `Iter`, which //! represents iteration over a slice. //! -//! ## Traits -//! -//! A number of traits add methods that allow you to accomplish tasks -//! with slices, the most important being `SliceExt`. Other traits -//! apply only to slices of elements satisfying certain bounds (like -//! `Ord`). -//! -//! An example is the `slice` method which enables slicing syntax `[a..b]` that -//! returns an immutable "view" into a `Vec` or another slice from the index -//! interval `[a, b)`: -//! -//! ```rust -//! fn main() { -//! let numbers = [0, 1, 2]; -//! let last_numbers = &numbers[1..3]; -//! // last_numbers is now &[1, 2] -//! } -//! ``` -//! -//! ## Implementations of other traits +//! ## Trait Implementations //! //! There are several implementations of common traits for slices. Some examples //! include: //! //! * `Clone` -//! * `Eq`, `Ord` - for immutable slices whose element type are `Eq` or `Ord`. +//! * `Eq`, `Ord` - for slices whose element type are `Eq` or `Ord`. //! * `Hash` - for slices whose element type is `Hash` //! //! ## Iteration //! -//! The method `iter()` returns an iteration value for a slice. The iterator -//! yields references to the slice's elements, so if the element -//! type of the slice is `isize`, the element type of the iterator is `&isize`. +//! The slices implement `IntoIterator`. The iterators of yield references +//! to the slice elements. //! -//! ```rust -//! let numbers = [0, 1, 2]; -//! for &x in numbers.iter() { -//! println!("{} is a number!", x); +//! ``` +//! let numbers = &[0, 1, 2]; +//! for n in numbers { +//! println!("{} is a number!", n); //! } //! ``` //! -//! * `.iter_mut()` returns an iterator that allows modifying each value. -//! * Further iterators exist that split, chunk or permute the slice. +//! The mutable slice yields mutable references to the elements: +//! +//! ``` +//! let mut scores = [7, 8, 9]; +//! for score in &mut scores[..] { +//! *score += 1; +//! } +//! ``` +//! +//! This iterator yields mutable references to the slice's elements, so while the element +//! type of the slice is `i32`, the element type of the iterator is `&mut i32`. +//! +//! * `.iter()` and `.iter_mut()` are the explicit methods to return the default +//! iterators. +//! * Further methods that return iterators are `.split()`, `.splitn()`, +//! `.chunks()`, `.windows()` and more. #![doc(primitive = "slice")] #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ca2786e843e97..aaa73badcac99 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -19,7 +19,7 @@ //! are owned elsewhere. //! //! Basic operations are implemented directly by the compiler, but more advanced -//! operations are defined on the [`StrExt`](trait.StrExt.html) trait. +//! operations are defined as methods on the `str` type. //! //! # Examples //! diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index ea98f6f5f2461..a629e0308e982 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -165,8 +165,7 @@ impl FromStr for bool { /// assert!(::from_str("not even a boolean").is_err()); /// ``` /// - /// Note, in many cases, the StrExt::parse() which is based on - /// this FromStr::from_str() is more proper. + /// Note, in many cases, the `.parse()` method on `str` is more proper. /// /// ``` /// assert_eq!("true".parse(), Ok(true)); @@ -531,7 +530,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { /// External iterator for a string's bytes. /// Use with the `std::iter` module. /// -/// Created with `StrExt::bytes` +/// Created with `str::bytes` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] pub struct Bytes<'a>(Map, BytesDeref>); @@ -1489,27 +1488,27 @@ impl<'a, S: ?Sized> Str for &'a S where S: Str { fn as_slice(&self) -> &str { Str::as_slice(*self) } } -/// Return type of `StrExt::split` +/// Return type of `str::split` #[stable(feature = "rust1", since = "1.0.0")] pub struct Split<'a, P: Pattern<'a>>(CharSplits<'a, P>); delegate_iter!{pattern &'a str : Split<'a, P>} -/// Return type of `StrExt::split_terminator` +/// Return type of `str::split_terminator` #[stable(feature = "rust1", since = "1.0.0")] pub struct SplitTerminator<'a, P: Pattern<'a>>(CharSplits<'a, P>); delegate_iter!{pattern &'a str : SplitTerminator<'a, P>} -/// Return type of `StrExt::splitn` +/// Return type of `str::splitn` #[stable(feature = "rust1", since = "1.0.0")] pub struct SplitN<'a, P: Pattern<'a>>(CharSplitsN<'a, P>); delegate_iter!{pattern forward &'a str : SplitN<'a, P>} -/// Return type of `StrExt::rsplit` +/// Return type of `str::rsplit` #[stable(feature = "rust1", since = "1.0.0")] pub struct RSplit<'a, P: Pattern<'a>>(RCharSplits<'a, P>); delegate_iter!{pattern reverse &'a str : RSplit<'a, P>} -/// Return type of `StrExt::rsplitn` +/// Return type of `str::rsplitn` #[stable(feature = "rust1", since = "1.0.0")] pub struct RSplitN<'a, P: Pattern<'a>>(RCharSplitsN<'a, P>); delegate_iter!{pattern reverse &'a str : RSplitN<'a, P>} diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index eb759393ac6ec..c48b63cdcb6c4 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -1352,12 +1352,12 @@ impl<'tcx> euv::Delegate<'tcx> for ReassignmentChecker { fn mutate(&mut self, _: ast::NodeId, _: Span, cmt: mc::cmt, _: euv::MutateMode) { match cmt.cat { mc::cat_upvar(mc::Upvar { id: ty::UpvarId { var_id: vid, .. }, .. }) | - mc::cat_local(vid) => self.reassigned = self.node == vid, + mc::cat_local(vid) => self.reassigned |= self.node == vid, mc::cat_interior(ref base_cmt, mc::InteriorField(field)) => { match base_cmt.cat { mc::cat_upvar(mc::Upvar { id: ty::UpvarId { var_id: vid, .. }, .. }) | mc::cat_local(vid) => { - self.reassigned = self.node == vid && Some(field) == self.field + self.reassigned |= self.node == vid && Some(field) == self.field }, _ => {} } diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 4d7431a20b707..ba8de6da42f72 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -1766,6 +1766,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ast::BiAdd => { if is_float { FAdd(bcx, lhs, rhs, binop_debug_loc) + } else if is_simd { + Add(bcx, lhs, rhs, binop_debug_loc) } else { let (newbcx, res) = with_overflow_check( bcx, OverflowOp::Add, info, lhs_t, lhs, rhs, binop_debug_loc); @@ -1776,6 +1778,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ast::BiSub => { if is_float { FSub(bcx, lhs, rhs, binop_debug_loc) + } else if is_simd { + Sub(bcx, lhs, rhs, binop_debug_loc) } else { let (newbcx, res) = with_overflow_check( bcx, OverflowOp::Sub, info, lhs_t, lhs, rhs, binop_debug_loc); @@ -1786,6 +1790,8 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ast::BiMul => { if is_float { FMul(bcx, lhs, rhs, binop_debug_loc) + } else if is_simd { + Mul(bcx, lhs, rhs, binop_debug_loc) } else { let (newbcx, res) = with_overflow_check( bcx, OverflowOp::Mul, info, lhs_t, lhs, rhs, binop_debug_loc); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c6ae4d0dbec7d..0ed6d07bf7918 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -631,14 +631,14 @@ pub trait BufRead: Read { /// A `Write` adaptor which will write data to multiple locations. /// -/// For more information, see `WriteExt::broadcast`. -#[unstable(feature = "io", reason = "awaiting stability of WriteExt::broadcast")] +/// For more information, see `Write::broadcast`. +#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast")] pub struct Broadcast { first: T, second: U, } -#[unstable(feature = "io", reason = "awaiting stability of WriteExt::broadcast")] +#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast")] impl Write for Broadcast { fn write(&mut self, data: &[u8]) -> Result { let n = try!(self.first.write(data)); @@ -654,7 +654,7 @@ impl Write for Broadcast { /// Adaptor to chain together two instances of `Read`. /// -/// For more information, see `ReadExt::chain`. +/// For more information, see `Read::chain`. #[stable(feature = "rust1", since = "1.0.0")] pub struct Chain { first: T, @@ -677,7 +677,7 @@ impl Read for Chain { /// Reader adaptor which limits the bytes read from an underlying reader. /// -/// For more information, see `ReadExt::take`. +/// For more information, see `Read::take`. #[stable(feature = "rust1", since = "1.0.0")] pub struct Take { inner: T, @@ -730,14 +730,14 @@ impl BufRead for Take { /// An adaptor which will emit all read data to a specified writer as well. /// -/// For more information see `ReadExt::tee` -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::tee")] +/// For more information see `Read::tee` +#[unstable(feature = "io", reason = "awaiting stability of Read::tee")] pub struct Tee { reader: R, writer: W, } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::tee")] +#[unstable(feature = "io", reason = "awaiting stability of Read::tee")] impl Read for Tee { fn read(&mut self, buf: &mut [u8]) -> Result { let n = try!(self.reader.read(buf)); @@ -749,7 +749,7 @@ impl Read for Tee { /// A bridge from implementations of `Read` to an `Iterator` of `u8`. /// -/// See `ReadExt::bytes` for more information. +/// See `Read::bytes` for more information. #[stable(feature = "rust1", since = "1.0.0")] pub struct Bytes { inner: R, @@ -771,8 +771,8 @@ impl Iterator for Bytes { /// A bridge from implementations of `Read` to an `Iterator` of `char`. /// -/// See `ReadExt::chars` for more information. -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +/// See `Read::chars` for more information. +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] pub struct Chars { inner: R, } @@ -780,7 +780,7 @@ pub struct Chars { /// An enumeration of possible errors that can be generated from the `Chars` /// adapter. #[derive(PartialEq, Clone, Debug)] -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] pub enum CharsError { /// Variant representing that the underlying stream was read successfully /// but it did not contain valid utf8 data. @@ -790,7 +790,7 @@ pub enum CharsError { Other(Error), } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl Iterator for Chars { type Item = result::Result; @@ -822,7 +822,7 @@ impl Iterator for Chars { } } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl std_error::Error for CharsError { fn description(&self) -> &str { match *self { @@ -838,7 +838,7 @@ impl std_error::Error for CharsError { } } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl fmt::Display for CharsError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libstd/io/prelude.rs b/src/libstd/io/prelude.rs index a2ceacbe1f897..333ae8f26a0d7 100644 --- a/src/libstd/io/prelude.rs +++ b/src/libstd/io/prelude.rs @@ -18,7 +18,7 @@ //! ``` //! //! This module contains reexports of many core I/O traits such as `Read`, -//! `Write`, `ReadExt`, and `WriteExt`. Structures and functions are not +//! `Write` and `BufRead`. Structures and functions are not //! contained in this module. #![stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 6c191689255bc..c73d30d543ac5 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -206,7 +206,7 @@ pub fn current_exe() -> io::Result { if err != 0 { return Err(io::Error::last_os_error()); } if sz == 0 { return Err(io::Error::last_os_error()); } v.set_len(sz as uint - 1); // chop off trailing NUL - Ok(PathBuf::new::(OsStringExt::from_vec(v))) + Ok(PathBuf::from(OsString::from_vec(v))) } } @@ -232,7 +232,7 @@ pub fn current_exe() -> io::Result { Err(io::Error::last_os_error()) } else { let vec = CStr::from_ptr(v).to_bytes().to_vec(); - Ok(PathBuf::new::(OsStringExt::from_vec(vec))) + Ok(PathBuf::from(OsString::from_vec(vec))) } } } @@ -345,7 +345,7 @@ pub fn args() -> Args { let utf_c_str: *const libc::c_char = mem::transmute(objc_msgSend(tmp, utf8_sel)); let bytes = CStr::from_ptr(utf_c_str).to_bytes(); - res.push(OsString::from_str(str::from_utf8(bytes).unwrap())) + res.push(OsString::from(str::from_utf8(bytes).unwrap())) } } diff --git a/src/test/run-pass/issue-23037.rs b/src/test/run-pass/issue-23037.rs new file mode 100644 index 0000000000000..5257daa047af8 --- /dev/null +++ b/src/test/run-pass/issue-23037.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(core)] + +use std::simd::i32x4; +fn main() { + let foo = i32x4(1,2,3,4); + let bar = i32x4(40,30,20,10); + let baz = foo + bar; + assert!(baz.0 == 41 && baz.1 == 32 && baz.2 == 23 && baz.3 == 14); +} diff --git a/src/test/run-pass/match-reassign.rs b/src/test/run-pass/match-reassign.rs new file mode 100644 index 0000000000000..759296ad46b87 --- /dev/null +++ b/src/test/run-pass/match-reassign.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for #23698: The reassignment checker only cared +// about the last assigment in a match arm body + +// Use an extra function to make sure no extra assignments +// are introduced by macros in the match statement +fn check_eq(x: i32, y: i32) { + assert_eq!(x, y); +} + +#[allow(unused_assignments)] +fn main() { + let mut x = Box::new(1); + match x { + y => { + x = Box::new(2); + let _tmp = 1; // This assignment used to throw off the reassignment checker + check_eq(*y, 1); + } + } +}