1
Fork 0

core: mark relevant functions with #[rustc_inherit_overflow_checks].

This commit is contained in:
Eduard Burtescu 2016-05-26 19:02:26 +03:00
parent 4adc967ed1
commit 702c47baae
4 changed files with 19 additions and 3 deletions

View file

@ -172,6 +172,7 @@ pub trait Iterator {
/// assert_eq!(a.iter().count(), 5); /// assert_eq!(a.iter().count(), 5);
/// ``` /// ```
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn count(self) -> usize where Self: Sized { fn count(self) -> usize where Self: Sized {
// Might overflow. // Might overflow.

View file

@ -510,6 +510,7 @@ impl<A, B> Iterator for Chain<A, B> where
} }
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn count(self) -> usize { fn count(self) -> usize {
match self.state { match self.state {
ChainState::Both => self.a.count() + self.b.count(), ChainState::Both => self.a.count() + self.b.count(),
@ -932,6 +933,7 @@ impl<I> Iterator for Enumerate<I> where I: Iterator {
/// ///
/// Might panic if the index of the element overflows a `usize`. /// Might panic if the index of the element overflows a `usize`.
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn next(&mut self) -> Option<(usize, <I as Iterator>::Item)> { fn next(&mut self) -> Option<(usize, <I as Iterator>::Item)> {
self.iter.next().map(|a| { self.iter.next().map(|a| {
let ret = (self.count, a); let ret = (self.count, a);
@ -947,6 +949,7 @@ impl<I> Iterator for Enumerate<I> where I: Iterator {
} }
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn nth(&mut self, n: usize) -> Option<(usize, I::Item)> { fn nth(&mut self, n: usize) -> Option<(usize, I::Item)> {
self.iter.nth(n).map(|a| { self.iter.nth(n).map(|a| {
let i = self.count + n; let i = self.count + n;
@ -1008,6 +1011,7 @@ impl<I: Iterator> Iterator for Peekable<I> {
} }
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn count(self) -> usize { fn count(self) -> usize {
(if self.peeked.is_some() { 1 } else { 0 }) + self.iter.count() (if self.peeked.is_some() { 1 } else { 0 }) + self.iter.count()
} }

View file

@ -1033,7 +1033,7 @@ macro_rules! int_impl {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD. #[rustc_inherit_overflow_checks]
pub fn pow(self, mut exp: u32) -> Self { pub fn pow(self, mut exp: u32) -> Self {
let mut base = self; let mut base = self;
let mut acc = Self::one(); let mut acc = Self::one();
@ -1075,7 +1075,7 @@ macro_rules! int_impl {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD. #[rustc_inherit_overflow_checks]
pub fn abs(self) -> Self { pub fn abs(self) -> Self {
if self.is_negative() { if self.is_negative() {
// Note that the #[inline] above means that the overflow // Note that the #[inline] above means that the overflow
@ -2061,7 +2061,7 @@ macro_rules! uint_impl {
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD. #[rustc_inherit_overflow_checks]
pub fn pow(self, mut exp: u32) -> Self { pub fn pow(self, mut exp: u32) -> Self {
let mut base = self; let mut base = self;
let mut acc = Self::one(); let mut acc = Self::one();

View file

@ -208,6 +208,7 @@ macro_rules! add_impl {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn add(self, other: $t) -> $t { self + other } fn add(self, other: $t) -> $t { self + other }
} }
@ -261,6 +262,7 @@ macro_rules! sub_impl {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn sub(self, other: $t) -> $t { self - other } fn sub(self, other: $t) -> $t { self - other }
} }
@ -314,6 +316,7 @@ macro_rules! mul_impl {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn mul(self, other: $t) -> $t { self * other } fn mul(self, other: $t) -> $t { self * other }
} }
@ -511,6 +514,7 @@ macro_rules! neg_impl_core {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn neg(self) -> $t { let $id = self; $body } fn neg(self) -> $t { let $id = self; $body }
} }
@ -788,6 +792,7 @@ macro_rules! shl_impl {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn shl(self, other: $f) -> $t { fn shl(self, other: $f) -> $t {
self << other self << other
} }
@ -859,6 +864,7 @@ macro_rules! shr_impl {
type Output = $t; type Output = $t;
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn shr(self, other: $f) -> $t { fn shr(self, other: $f) -> $t {
self >> other self >> other
} }
@ -923,6 +929,7 @@ macro_rules! add_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")] #[stable(feature = "op_assign_traits", since = "1.8.0")]
impl AddAssign for $t { impl AddAssign for $t {
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn add_assign(&mut self, other: $t) { *self += other } fn add_assign(&mut self, other: $t) { *self += other }
} }
)+) )+)
@ -967,6 +974,7 @@ macro_rules! sub_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")] #[stable(feature = "op_assign_traits", since = "1.8.0")]
impl SubAssign for $t { impl SubAssign for $t {
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn sub_assign(&mut self, other: $t) { *self -= other } fn sub_assign(&mut self, other: $t) { *self -= other }
} }
)+) )+)
@ -1011,6 +1019,7 @@ macro_rules! mul_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")] #[stable(feature = "op_assign_traits", since = "1.8.0")]
impl MulAssign for $t { impl MulAssign for $t {
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn mul_assign(&mut self, other: $t) { *self *= other } fn mul_assign(&mut self, other: $t) { *self *= other }
} }
)+) )+)
@ -1275,6 +1284,7 @@ macro_rules! shl_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")] #[stable(feature = "op_assign_traits", since = "1.8.0")]
impl ShlAssign<$f> for $t { impl ShlAssign<$f> for $t {
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn shl_assign(&mut self, other: $f) { fn shl_assign(&mut self, other: $f) {
*self <<= other *self <<= other
} }
@ -1337,6 +1347,7 @@ macro_rules! shr_assign_impl {
#[stable(feature = "op_assign_traits", since = "1.8.0")] #[stable(feature = "op_assign_traits", since = "1.8.0")]
impl ShrAssign<$f> for $t { impl ShrAssign<$f> for $t {
#[inline] #[inline]
#[rustc_inherit_overflow_checks]
fn shr_assign(&mut self, other: $f) { fn shr_assign(&mut self, other: $f) {
*self >>= other *self >>= other
} }