diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-08-10 14:05:58 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-08-10 14:05:58 -0700 |
| commit | b8aa595e6d159bfb5e0293659b69e0edc457a468 (patch) | |
| tree | 01c3c1ef7415103c4d48a28cf57be47cba5cc624 /src/libcore | |
| parent | be95ca4b17203a3aed27c17c1e93b76c9477e5bc (diff) | |
| parent | b6179602bea71607a9ea63197eca423fcce5f7b0 (diff) | |
Merge remote-tracking branch 'origin/master' into gen
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cmp.rs | 7 | ||||
| -rw-r--r-- | src/libcore/iter/range.rs | 13 | ||||
| -rw-r--r-- | src/libcore/macros.rs | 14 | ||||
| -rw-r--r-- | src/libcore/ops/function.rs | 2 | ||||
| -rw-r--r-- | src/libcore/option.rs | 2 | ||||
| -rw-r--r-- | src/libcore/result.rs | 2 | ||||
| -rw-r--r-- | src/libcore/tests/slice.rs | 12 |
7 files changed, 38 insertions, 14 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index a9f55dc2788..ec6525485f7 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -110,11 +110,13 @@ use self::Ordering::*; pub trait PartialEq<Rhs: ?Sized = Self> { /// This method tests for `self` and `other` values to be equal, and is used /// by `==`. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn eq(&self, other: &Rhs) -> bool; /// This method tests for `!=`. #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } @@ -625,6 +627,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { /// let result = std::f64::NAN.partial_cmp(&1.0); /// assert_eq!(result, None); /// ``` + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>; @@ -640,6 +643,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { /// assert_eq!(result, false); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn lt(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { @@ -661,6 +665,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { /// assert_eq!(result, true); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn le(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { @@ -681,6 +686,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { /// assert_eq!(result, false); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn gt(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { @@ -702,6 +708,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { /// assert_eq!(result, true); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn ge(&self, other: &Rhs) -> bool { match self.partial_cmp(other) { diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 32c32e327eb..73d518b570a 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -214,9 +214,16 @@ impl<A: Step> Iterator for ops::Range<A> { #[inline] fn next(&mut self) -> Option<A> { if self.start < self.end { - let mut n = self.start.add_one(); - mem::swap(&mut n, &mut self.start); - Some(n) + // We check for overflow here, even though it can't actually + // happen. Adding this check does however help llvm vectorize loops + // for some ranges that don't get vectorized otherwise, + // and this won't actually result in an extra check in an optimized build. + if let Some(mut n) = self.start.add_usize(1) { + mem::swap(&mut n, &mut self.start); + Some(n) + } else { + None + } } else { None } diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 2edf8e1fa88..684b81a27f8 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -8,6 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[macro_export] +// This stability attribute is totally useless. +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg(stage0)] +macro_rules! __rust_unstable_column { + () => { + column!() + } +} + /// Entry point of thread panic, for details, see std::macros #[macro_export] #[allow_internal_unstable] @@ -18,7 +28,7 @@ macro_rules! panic { ); ($msg:expr) => ({ static _MSG_FILE_LINE_COL: (&'static str, &'static str, u32, u32) = - ($msg, file!(), line!(), column!()); + ($msg, file!(), line!(), __rust_unstable_column!()); $crate::panicking::panic(&_MSG_FILE_LINE_COL) }); ($fmt:expr, $($arg:tt)*) => ({ @@ -27,7 +37,7 @@ macro_rules! panic { // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. static _MSG_FILE_LINE_COL: (&'static str, u32, u32) = - (file!(), line!(), column!()); + (file!(), line!(), __rust_unstable_column!()); $crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_MSG_FILE_LINE_COL) }); } diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index 62bf69336a3..c5b3fbca1a6 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -187,7 +187,7 @@ mod impls { where F : FnMut<A> { type Output = F::Output; - extern "rust-call" fn call_once(mut self, args: A) -> F::Output { + extern "rust-call" fn call_once(self, args: A) -> F::Output { (*self).call_mut(args) } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index ef41b679410..aecf2ee9325 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -872,7 +872,7 @@ impl<'a, T> IntoIterator for &'a mut Option<T> { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; - fn into_iter(mut self) -> IterMut<'a, T> { + fn into_iter(self) -> IterMut<'a, T> { self.iter_mut() } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 88a93492de9..20cfb02afcc 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -909,7 +909,7 @@ impl<'a, T, E> IntoIterator for &'a mut Result<T, E> { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; - fn into_iter(mut self) -> IterMut<'a, T> { + fn into_iter(self) -> IterMut<'a, T> { self.iter_mut() } } diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index e5d6b53b570..8c31d2e83d3 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -105,27 +105,27 @@ fn test_chunks_last() { #[test] fn test_chunks_mut_count() { - let mut v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; + let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; let c = v.chunks_mut(3); assert_eq!(c.count(), 2); - let mut v2: &mut [i32] = &mut [0, 1, 2, 3, 4]; + let v2: &mut [i32] = &mut [0, 1, 2, 3, 4]; let c2 = v2.chunks_mut(2); assert_eq!(c2.count(), 3); - let mut v3: &mut [i32] = &mut []; + let v3: &mut [i32] = &mut []; let c3 = v3.chunks_mut(2); assert_eq!(c3.count(), 0); } #[test] fn test_chunks_mut_nth() { - let mut v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; + let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; let mut c = v.chunks_mut(2); assert_eq!(c.nth(1).unwrap()[1], 3); assert_eq!(c.next().unwrap()[0], 4); - let mut v2: &mut [i32] = &mut [0, 1, 2, 3, 4]; + let v2: &mut [i32] = &mut [0, 1, 2, 3, 4]; let mut c2 = v2.chunks_mut(3); assert_eq!(c2.nth(1).unwrap()[1], 4); assert_eq!(c2.next(), None); @@ -194,7 +194,7 @@ fn get_range() { #[test] fn get_mut_range() { - let mut v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; + let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5]; assert_eq!(v.get_mut(..), Some(&mut [0, 1, 2, 3, 4, 5][..])); assert_eq!(v.get_mut(..2), Some(&mut [0, 1][..])); assert_eq!(v.get_mut(2..), Some(&mut [2, 3, 4, 5][..])); |
