From 118b975c805533bab31f8155ad0af29b3635d3fc Mon Sep 17 00:00:00 2001 From: Nathan Kleyn Date: Tue, 8 Mar 2016 23:27:24 +0000 Subject: [PATCH 01/13] Add missing documentation examples for BinaryHeap. As part of the ongoing effort to document all methods with examples, this commit adds the missing examples for the `BinaryHeap` collection type. This is part of issue #29348. --- src/libcollections/binary_heap.rs | 106 ++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index bd329949618..efd56bdb264 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -167,6 +167,49 @@ use vec::{self, Vec}; /// item's ordering relative to any other item, as determined by the `Ord` /// trait, changes while it is in the heap. This is normally only possible /// through `Cell`, `RefCell`, global state, I/O, or unsafe code. +/// +/// # Examples +/// +/// ``` +/// use std::collections::BinaryHeap; +/// +/// // type inference lets us omit an explicit type signature (which +/// // would be `BinaryHeap` in this example). +/// let mut heap = BinaryHeap::new(); +/// +/// // We can use peek to look at the next item in the heap. In this case, +/// // there's no items in there yet so we get None. +/// assert_eq!(heap.peek(), None); +/// +/// // Let's add some scores... +/// heap.push(1); +/// heap.push(5); +/// heap.push(2); +/// +/// // Now peek shows the most important item in the heap. +/// assert_eq!(heap.peek(), Some(&5)); +/// +/// // We can check the length of a heap. +/// assert_eq!(heap.len(), 3); +/// +/// // We can iterate over the items in the heap, although they are returned in +/// // a random order. +/// for x in heap.iter() { +/// println!("{}", x); +/// } +/// +/// // If we instead pop these scores, they should come back in order. +/// assert_eq!(heap.pop(), Some(5)); +/// assert_eq!(heap.pop(), Some(2)); +/// assert_eq!(heap.pop(), Some(1)); +/// assert_eq!(heap.pop(), None); +/// +/// // We can clear the heap of any remaining items. +/// heap.clear(); +/// +/// // The heap should now be empty. +/// assert!(heap.is_empty()) +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct BinaryHeap { data: Vec, @@ -331,6 +374,17 @@ impl BinaryHeap { } /// Discards as much additional capacity as possible. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BinaryHeap; + /// let mut heap: BinaryHeap = BinaryHeap::with_capacity(100); + /// + /// assert!(heap.capacity() >= 100); + /// heap.shrink_to_fit(); + /// assert!(heap.capacity() == 0); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn shrink_to_fit(&mut self) { self.data.shrink_to_fit(); @@ -571,12 +625,36 @@ impl BinaryHeap { } /// Returns the length of the binary heap. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BinaryHeap; + /// let mut heap = BinaryHeap::from(vec![1, 3]); + /// + /// assert_eq!(heap.len(), 2); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn len(&self) -> usize { self.data.len() } /// Checks if the binary heap is empty. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BinaryHeap; + /// let mut heap = BinaryHeap::new(); + /// + /// assert!(heap.is_empty()); + /// + /// heap.push(3); + /// heap.push(5); + /// heap.push(1); + /// + /// assert!(!heap.is_empty()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn is_empty(&self) -> bool { self.len() == 0 @@ -585,6 +663,21 @@ impl BinaryHeap { /// Clears the binary heap, returning an iterator over the removed elements. /// /// The elements are removed in arbitrary order. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BinaryHeap; + /// let mut heap = BinaryHeap::from(vec![1, 3]); + /// + /// assert!(!heap.is_empty()); + /// + /// for x in heap.drain() { + /// println!("{}", x); + /// } + /// + /// assert!(heap.is_empty()); + /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] pub fn drain(&mut self) -> Drain { @@ -592,6 +685,19 @@ impl BinaryHeap { } /// Drops all items from the binary heap. + /// + /// # Examples + /// + /// ``` + /// use std::collections::BinaryHeap; + /// let mut heap = BinaryHeap::from(vec![1, 3]); + /// + /// assert!(!heap.is_empty()); + /// + /// heap.clear(); + /// + /// assert!(heap.is_empty()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn clear(&mut self) { self.drain(); From 04436fb65b7efa81793f0f89cf375d0fadf99f89 Mon Sep 17 00:00:00 2001 From: Nathan Kleyn Date: Wed, 9 Mar 2016 16:18:31 +0000 Subject: [PATCH 02/13] Address review comments to add "basic usage" sections to docs. --- src/libcollections/binary_heap.rs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index efd56bdb264..29258180c67 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -246,6 +246,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -263,6 +265,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::with_capacity(10); @@ -278,6 +282,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from(vec![1, 2, 3, 4]); @@ -296,6 +302,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -316,6 +324,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::with_capacity(100); @@ -340,6 +350,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -361,6 +373,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -377,6 +391,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap: BinaryHeap = BinaryHeap::with_capacity(100); @@ -395,6 +411,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from(vec![1, 3]); @@ -418,6 +436,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -440,6 +460,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// #![feature(binary_heap_extras)] /// @@ -478,6 +500,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// #![feature(binary_heap_extras)] /// @@ -508,6 +532,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 7]); @@ -528,6 +554,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// @@ -628,6 +656,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from(vec![1, 3]); @@ -643,6 +673,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -666,6 +698,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from(vec![1, 3]); @@ -688,6 +722,8 @@ impl BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from(vec![1, 3]); @@ -915,6 +951,8 @@ impl IntoIterator for BinaryHeap { /// /// # Examples /// + /// Basic usage: + /// /// ``` /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from(vec![1, 2, 3, 4]); From ca129e376e16693e6974b813ab6fa0cc33e22387 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 9 Mar 2016 10:12:24 -0800 Subject: [PATCH 03/13] lint: mark associated types as live for the dead_code pass --- src/librustc/middle/dead.rs | 12 +++------ .../lint-dead-code-associated-type.rs | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/test/run-pass/lint-dead-code-associated-type.rs diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index f1b38ea8b81..4ceac287d19 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -351,15 +351,9 @@ impl<'v> Visitor<'v> for LifeSeeder { } hir::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => { for impl_item in impl_items { - match impl_item.node { - hir::ImplItemKind::Const(..) | - hir::ImplItemKind::Method(..) => { - if opt_trait.is_some() || - has_allow_dead_code_or_lang_attr(&impl_item.attrs) { - self.worklist.push(impl_item.id); - } - } - hir::ImplItemKind::Type(_) => {} + if opt_trait.is_some() || + has_allow_dead_code_or_lang_attr(&impl_item.attrs) { + self.worklist.push(impl_item.id); } } } diff --git a/src/test/run-pass/lint-dead-code-associated-type.rs b/src/test/run-pass/lint-dead-code-associated-type.rs new file mode 100644 index 00000000000..1ae078ba221 --- /dev/null +++ b/src/test/run-pass/lint-dead-code-associated-type.rs @@ -0,0 +1,27 @@ +// Copyright 2016 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. + +#![deny(dead_code)] + +trait Foo { + type Bar; +} + +struct Used; + +struct Ex; + +impl Foo for Ex { + type Bar = Used; +} + +pub fn main() { + let _x = Ex; +} From e1048b5ab64cceba5ce8edb1f41614e063edb78d Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 9 Mar 2016 21:44:35 -0800 Subject: [PATCH 04/13] Prefer `Option::expect` over explicit unwrapping. --- src/compiletest/errors.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 44634e4d565..264e32f1d06 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -93,9 +93,8 @@ fn parse_expected(last_nonfollow_error: Option, let (which, line) = if follow { assert!(adjusts == 0, "use either //~| or //~^, not both."); - let line = last_nonfollow_error.unwrap_or_else(|| { - panic!("encountered //~| without preceding //~^ line.") - }); + let line = last_nonfollow_error.expect("encountered //~| without \ + preceding //~^ line."); (FollowPrevious(line), line) } else { let which = From 410333be64c23e9b38c81cdd14cae20cffa3f3c8 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 9 Mar 2016 22:13:51 -0800 Subject: [PATCH 05/13] Differentiate "line" and "line number" variable names. --- src/compiletest/errors.rs | 25 ++++++++++++------------- src/compiletest/runtest.rs | 4 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 264e32f1d06..c1fbfcda475 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -15,7 +15,7 @@ use std::io::prelude::*; use std::path::Path; pub struct ExpectedError { - pub line: usize, + pub line_num: usize, pub kind: String, pub msg: String, } @@ -53,15 +53,15 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec { rdr.lines() .enumerate() - .filter_map(|(line_no, ln)| { + .filter_map(|(line_num, line)| { parse_expected(last_nonfollow_error, - line_no + 1, - &ln.unwrap(), + line_num + 1, + &line.unwrap(), &tag) .map(|(which, error)| { match which { FollowPrevious(_) => {} - _ => last_nonfollow_error = Some(error.line), + _ => last_nonfollow_error = Some(error.line_num), } error }) @@ -91,22 +91,21 @@ fn parse_expected(last_nonfollow_error: Option, .skip_while(|c| !c.is_whitespace()) .collect::().trim().to_owned(); - let (which, line) = if follow { + let (which, line_num) = if follow { assert!(adjusts == 0, "use either //~| or //~^, not both."); - let line = last_nonfollow_error.expect("encountered //~| without \ - preceding //~^ line."); - (FollowPrevious(line), line) + let line_num = last_nonfollow_error.expect("encountered //~| without \ + preceding //~^ line."); + (FollowPrevious(line_num), line_num) } else { let which = if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine }; - let line = line_num - adjusts; - (which, line) + let line_num = line_num - adjusts; + (which, line_num) }; debug!("line={} tag={:?} which={:?} kind={:?} msg={:?}", line_num, tag, which, kind, msg); - - Some((which, ExpectedError { line: line, + Some((which, ExpectedError { line_num: line_num, kind: kind, msg: msg, })) } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1d2f560f5f6..8c3ee3fb5f4 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1004,7 +1004,7 @@ fn check_expected_errors(revision: Option<&str>, } let prefixes = expected_errors.iter().map(|ee| { - let expected = format!("{}:{}:", testpaths.file.display(), ee.line); + let expected = format!("{}:{}:", testpaths.file.display(), ee.line_num); // On windows just translate all '\' path separators to '/' expected.replace(r"\", "/") }).collect::>(); @@ -1076,7 +1076,7 @@ fn check_expected_errors(revision: Option<&str>, if !flag { let ee = &expected_errors[i]; error(revision, &format!("expected {} on line {} not found: {}", - ee.kind, ee.line, ee.msg)); + ee.kind, ee.line_num, ee.msg)); not_found += 1; } } From da4fda44e742671c9451b0b0fd811a5626828041 Mon Sep 17 00:00:00 2001 From: Nathan Kleyn Date: Thu, 10 Mar 2016 11:40:31 +0000 Subject: [PATCH 06/13] Remove unnecessary mut in docs causing test failures. --- src/libcollections/binary_heap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 29258180c67..ba317334cfa 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -660,7 +660,7 @@ impl BinaryHeap { /// /// ``` /// use std::collections::BinaryHeap; - /// let mut heap = BinaryHeap::from(vec![1, 3]); + /// let heap = BinaryHeap::from(vec![1, 3]); /// /// assert_eq!(heap.len(), 2); /// ``` From 3d163218700364a67c1120aa437d7b8f229f0663 Mon Sep 17 00:00:00 2001 From: "Craig M. Brandenburg" Date: Thu, 10 Mar 2016 05:14:00 -0700 Subject: [PATCH 07/13] Spell fixes for std::ffi doc comments --- src/libstd/ffi/os_str.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index cf4f4bdf291..d979aa264af 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -22,7 +22,7 @@ use sys::os_str::{Buf, Slice}; use sys_common::{AsInner, IntoInner, FromInner}; /// A type that can represent owned, mutable platform-native strings, but is -/// cheaply interconvertable with Rust strings. +/// cheaply inter-convertible with Rust strings. /// /// The need for this type arises from the fact that: /// @@ -272,7 +272,7 @@ impl OsStr { unsafe { mem::transmute(inner) } } - /// Yields a `&str` slice if the `OsStr` is valid unicode. + /// Yields a `&str` slice if the `OsStr` is valid Unicode. /// /// This conversion may entail doing a check for UTF-8 validity. #[stable(feature = "rust1", since = "1.0.0")] @@ -301,7 +301,7 @@ impl OsStr { /// On Unix systems, this is a no-op. /// /// On Windows systems, this returns `None` unless the `OsStr` is - /// valid unicode, in which case it produces UTF-8-encoded + /// valid Unicode, in which case it produces UTF-8-encoded /// data. This may entail checking validity. #[unstable(feature = "convert", reason = "recently added", issue = "27704")] #[rustc_deprecated(reason = "RFC was closed, hides subtle Windows semantics", From 4d476693f0ccebeb1ca101d5915b1210de4e6246 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 10 Mar 2016 11:34:42 -0600 Subject: [PATCH 08/13] Update getting-started.md In `rustc 1.7.0` the message that is displayed is now `Rust is ready to roll.` --- src/doc/book/getting-started.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/doc/book/getting-started.md b/src/doc/book/getting-started.md index 31ee385a928..b0d4c6d6dd2 100644 --- a/src/doc/book/getting-started.md +++ b/src/doc/book/getting-started.md @@ -119,19 +119,7 @@ This will download a script, and start the installation. If it all goes well, you’ll see this appear: ```text -Welcome to Rust. - -This script will download the Rust compiler and its package manager, Cargo, and -install them to /usr/local. You may install elsewhere by running this script -with the --prefix= option. - -The installer will run under ‘sudo’ and may ask you for your password. If you do -not want the script to run ‘sudo’ then pass it the --disable-sudo flag. - -You may uninstall later by running /usr/local/lib/rustlib/uninstall.sh, -or by running this script again with the --uninstall flag. - -Continue? (y/N) +Rust is ready to roll. ``` From here, press `y` for ‘yes’, and then follow the rest of the prompts. From 266c41707147ea66f06b0ef8e3086c01f9791447 Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Fri, 11 Mar 2016 00:41:25 +0530 Subject: [PATCH 09/13] removed integer constants in librustc_typeck --- src/librustc_typeck/diagnostics.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index cfe76206b02..f376b42fbf9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -379,7 +379,7 @@ impl Test { fn main() { let x = Test; - let v = &[0i32]; + let v = &[0]; x.method::(v); // error: only one type parameter is expected! } @@ -398,7 +398,7 @@ impl Test { fn main() { let x = Test; - let v = &[0i32]; + let v = &[0]; x.method::(v); // OK, we're good! } @@ -901,7 +901,7 @@ Example of erroneous code: ```compile_fail enum Foo { FirstValue(i32) }; -let u = Foo::FirstValue { value: 0i32 }; // error: Foo::FirstValue +let u = Foo::FirstValue { value: 0 }; // error: Foo::FirstValue // isn't a structure! // or even simpler, if the name doesn't refer to a structure at all. let t = u32 { value: 4 }; // error: `u32` does not name a structure. From fe541b168e4122844dc4b7ebb7a1de1613958c34 Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Fri, 11 Mar 2016 01:32:03 +0530 Subject: [PATCH 10/13] removed suffixes for librustc_front --- src/librustc_front/hir.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index ece62364376..cc7c0f7865e 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -737,7 +737,7 @@ pub enum Expr_ { ExprBinary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) ExprUnary(UnOp, P), - /// A literal (For example: `1u8`, `"foo"`) + /// A literal (For example: `1`, `"foo"`) ExprLit(P), /// A cast (`foo as f64`) ExprCast(P, P), @@ -804,7 +804,7 @@ pub enum Expr_ { /// A vector literal constructed from one repeated element. /// - /// For example, `[1u8; 5]`. The first expression is the element + /// For example, `[1; 5]`. The first expression is the element /// to be repeated; the second is the number of times to repeat it. ExprRepeat(P, P), } From bfffe6d9d25d52f75705b5ebcc741b6844c2aa81 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Thu, 10 Mar 2016 21:36:43 +0100 Subject: [PATCH 11/13] Clarify doc for slice slicing (Index impls) This is a follow up for PR #32099 and #32057 --- src/libcore/slice.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 8acd0c8f2cf..823acf68001 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -535,6 +535,16 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! { // FIXME implement indexing with inclusive ranges +/// Implements slicing with syntax `&self[begin .. end]`. +/// +/// Returns a slice of self for the index range [`begin`..`end`). +/// +/// This operation is `O(1)`. +/// +/// # Panics +/// +/// Requires that `begin <= end` and `end <= self.len()`, +/// otherwise slicing will panic. #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; @@ -554,6 +564,13 @@ impl ops::Index> for [T] { } } } + +/// Implements slicing with syntax `&self[.. end]`. +/// +/// Returns a slice of self from the beginning until but not including +/// the index `end`. +/// +/// Equivalent to `&self[0 .. end]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; @@ -563,6 +580,12 @@ impl ops::Index> for [T] { self.index(0 .. index.end) } } + +/// Implements slicing with syntax `&self[begin ..]`. +/// +/// Returns a slice of self from and including the index `begin` until the end. +/// +/// Equivalent to `&self[begin .. self.len()]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; @@ -572,6 +595,12 @@ impl ops::Index> for [T] { self.index(index.start .. self.len()) } } + +/// Implements slicing with syntax `&self[..]`. +/// +/// Returns a slice of the whole slice. This operation can not panic. +/// +/// Equivalent to `&self[0 .. self.len()]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for [T] { type Output = [T]; @@ -608,6 +637,16 @@ impl ops::Index> for [T] { } } +/// Implements mutable slicing with syntax `&mut self[begin .. end]`. +/// +/// Returns a slice of self for the index range [`begin`..`end`). +/// +/// This operation is `O(1)`. +/// +/// # Panics +/// +/// Requires that `begin <= end` and `end <= self.len()`, +/// otherwise slicing will panic. #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { #[inline] @@ -625,6 +664,13 @@ impl ops::IndexMut> for [T] { } } } + +/// Implements mutable slicing with syntax `&mut self[.. end]`. +/// +/// Returns a slice of self from the beginning until but not including +/// the index `end`. +/// +/// Equivalent to `&mut self[0 .. end]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { #[inline] @@ -632,6 +678,12 @@ impl ops::IndexMut> for [T] { self.index_mut(0 .. index.end) } } + +/// Implements mutable slicing with syntax `&mut self[begin ..]`. +/// +/// Returns a slice of self from and including the index `begin` until the end. +/// +/// Equivalent to `&mut self[begin .. self.len()]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { #[inline] @@ -640,6 +692,12 @@ impl ops::IndexMut> for [T] { self.index_mut(index.start .. len) } } + +/// Implements mutable slicing with syntax `&mut self[..]`. +/// +/// Returns a slice of the whole slice. This operation can not panic. +/// +/// Equivalent to `&mut self[0 .. self.len()]` #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut for [T] { #[inline] From e1cc628549020207e07ce8271478f7baff602757 Mon Sep 17 00:00:00 2001 From: srinivasreddy Date: Fri, 11 Mar 2016 08:36:36 +0530 Subject: [PATCH 12/13] cleanup int suffixes in libcoretest --- src/libcoretest/fmt/builders.rs | 20 ++++++++++---------- src/libcoretest/iter.rs | 8 ++++---- src/libcoretest/num/int_macros.rs | 8 ++++---- src/libcoretest/num/mod.rs | 4 ++-- src/libcoretest/option.rs | 6 +++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libcoretest/fmt/builders.rs b/src/libcoretest/fmt/builders.rs index 885ee3f9c3b..e71e61bda5e 100644 --- a/src/libcoretest/fmt/builders.rs +++ b/src/libcoretest/fmt/builders.rs @@ -53,7 +53,7 @@ mod debug_struct { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("Foo") .field("bar", &true) - .field("baz", &format_args!("{}/{}", 10i32, 20i32)) + .field("baz", &format_args!("{}/{}", 10, 20)) .finish() } } @@ -75,7 +75,7 @@ mod debug_struct { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("Foo") .field("bar", &true) - .field("baz", &format_args!("{}/{}", 10i32, 20i32)) + .field("baz", &format_args!("{}/{}", 10, 20)) .finish() } } @@ -150,7 +150,7 @@ mod debug_tuple { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_tuple("Foo") .field(&true) - .field(&format_args!("{}/{}", 10i32, 20i32)) + .field(&format_args!("{}/{}", 10, 20)) .finish() } } @@ -172,7 +172,7 @@ mod debug_tuple { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_tuple("Foo") .field(&true) - .field(&format_args!("{}/{}", 10i32, 20i32)) + .field(&format_args!("{}/{}", 10, 20)) .finish() } } @@ -247,7 +247,7 @@ mod debug_map { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_map() .entry(&"bar", &true) - .entry(&10i32, &format_args!("{}/{}", 10i32, 20i32)) + .entry(&10, &format_args!("{}/{}", 10, 20)) .finish() } } @@ -269,7 +269,7 @@ mod debug_map { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_map() .entry(&"bar", &true) - .entry(&10i32, &format_args!("{}/{}", 10i32, 20i32)) + .entry(&10, &format_args!("{}/{}", 10, 20)) .finish() } } @@ -348,7 +348,7 @@ mod debug_set { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_set() .entry(&true) - .entry(&format_args!("{}/{}", 10i32, 20i32)) + .entry(&format_args!("{}/{}", 10, 20)) .finish() } } @@ -370,7 +370,7 @@ mod debug_set { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_set() .entry(&true) - .entry(&format_args!("{}/{}", 10i32, 20i32)) + .entry(&format_args!("{}/{}", 10, 20)) .finish() } } @@ -445,7 +445,7 @@ mod debug_list { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_list() .entry(&true) - .entry(&format_args!("{}/{}", 10i32, 20i32)) + .entry(&format_args!("{}/{}", 10, 20)) .finish() } } @@ -467,7 +467,7 @@ mod debug_list { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_list() .entry(&true) - .entry(&format_args!("{}/{}", 10i32, 20i32)) + .entry(&format_args!("{}/{}", 10, 20)) .finish() } } diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index acdced64928..6c0cb03b5f7 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -677,7 +677,7 @@ fn test_rev() { #[test] fn test_cloned() { - let xs = [2u8, 4, 6, 8]; + let xs = [2, 4, 6, 8]; let mut it = xs.iter().cloned(); assert_eq!(it.len(), 4); @@ -861,8 +861,8 @@ fn test_range() { assert_eq!((-10..-1).size_hint(), (9, Some(9))); assert_eq!((-1..-10).size_hint(), (0, Some(0))); - assert_eq!((-70..58i8).size_hint(), (128, Some(128))); - assert_eq!((-128..127i8).size_hint(), (255, Some(255))); + assert_eq!((-70..58).size_hint(), (128, Some(128))); + assert_eq!((-128..127).size_hint(), (255, Some(255))); assert_eq!((-2..isize::MAX).size_hint(), (isize::MAX as usize + 2, Some(isize::MAX as usize + 2))); } @@ -1013,7 +1013,7 @@ fn bench_max_by_key2(b: &mut Bencher) { array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0 } - let mut data = vec![0i32; 1638]; + let mut data = vec![0; 1638]; data[514] = 9999; b.iter(|| max_index_iter(&data)); diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index afcf836ad10..8d791283ab8 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -208,11 +208,11 @@ mod tests { fn test_pow() { let mut r = 2 as $T; - assert_eq!(r.pow(2u32), 4 as $T); - assert_eq!(r.pow(0u32), 1 as $T); + assert_eq!(r.pow(2), 4 as $T); + assert_eq!(r.pow(0), 1 as $T); r = -2 as $T; - assert_eq!(r.pow(2u32), 4 as $T); - assert_eq!(r.pow(3u32), -8 as $T); + assert_eq!(r.pow(2), 4 as $T); + assert_eq!(r.pow(3), -8 as $T); } } diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index fba56db32bb..11c1bd667fb 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -99,8 +99,8 @@ mod tests { #[test] fn test_leading_plus() { - assert_eq!("+127".parse::().ok(), Some(127u8)); - assert_eq!("+9223372036854775807".parse::().ok(), Some(9223372036854775807i64)); + assert_eq!("+127".parse::().ok(), Some(127)); + assert_eq!("+9223372036854775807".parse::().ok(), Some(9223372036854775807)); } #[test] diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index 3e564cf1970..51b0655f680 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -251,7 +251,7 @@ fn test_collect() { #[test] fn test_cloned() { - let val = 1u32; + let val = 1; let val_ref = &val; let opt_none: Option<&'static u32> = None; let opt_ref = Some(&val); @@ -263,10 +263,10 @@ fn test_cloned() { // Immutable ref works assert_eq!(opt_ref.clone(), Some(&val)); - assert_eq!(opt_ref.cloned(), Some(1u32)); + assert_eq!(opt_ref.cloned(), Some(1)); // Double Immutable ref works assert_eq!(opt_ref_ref.clone(), Some(&val_ref)); assert_eq!(opt_ref_ref.clone().cloned(), Some(&val)); - assert_eq!(opt_ref_ref.cloned().cloned(), Some(1u32)); + assert_eq!(opt_ref_ref.cloned().cloned(), Some(1)); } From e2b055c74a372f8405e7a903fb7c311109fabf92 Mon Sep 17 00:00:00 2001 From: Andrey Cherkashin Date: Fri, 11 Mar 2016 10:12:42 -0800 Subject: [PATCH 13/13] Add FreeBSD amd64 snapshot Snapshot itself: https://github.com/dhuseby/rust-manual-snapshots/pull/3 --- src/snapshots.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/snapshots.txt b/src/snapshots.txt index 9b3390d7747..3f9d8e5e9ec 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -6,6 +6,7 @@ S 2016-02-17 4d3eebf winnt-i386 0c336d794a65f8e285c121866c7d59aa2dd0d1e1 winnt-x86_64 27e75b1bf99770b3564bcebd7f3230be01135a92 openbsd-x86_64 ac957c6b84de2bd67f01df085d9ea515f96e22f3 + freebsd-x86_64 395adf223f3f25514c9dffecb524f493c42a0e5d S 2015-12-18 3391630 bitrig-x86_64 6476e1562df02389b55553b4c88b1f4fd121cd40