Skip to content

Commit 702c47b

Browse files
committed
core: mark relevant functions with #[rustc_inherit_overflow_checks].
1 parent 4adc967 commit 702c47b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/libcore/iter/iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub trait Iterator {
172172
/// assert_eq!(a.iter().count(), 5);
173173
/// ```
174174
#[inline]
175+
#[rustc_inherit_overflow_checks]
175176
#[stable(feature = "rust1", since = "1.0.0")]
176177
fn count(self) -> usize where Self: Sized {
177178
// Might overflow.

src/libcore/iter/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ impl<A, B> Iterator for Chain<A, B> where
510510
}
511511

512512
#[inline]
513+
#[rustc_inherit_overflow_checks]
513514
fn count(self) -> usize {
514515
match self.state {
515516
ChainState::Both => self.a.count() + self.b.count(),
@@ -932,6 +933,7 @@ impl<I> Iterator for Enumerate<I> where I: Iterator {
932933
///
933934
/// Might panic if the index of the element overflows a `usize`.
934935
#[inline]
936+
#[rustc_inherit_overflow_checks]
935937
fn next(&mut self) -> Option<(usize, <I as Iterator>::Item)> {
936938
self.iter.next().map(|a| {
937939
let ret = (self.count, a);
@@ -947,6 +949,7 @@ impl<I> Iterator for Enumerate<I> where I: Iterator {
947949
}
948950

949951
#[inline]
952+
#[rustc_inherit_overflow_checks]
950953
fn nth(&mut self, n: usize) -> Option<(usize, I::Item)> {
951954
self.iter.nth(n).map(|a| {
952955
let i = self.count + n;
@@ -1008,6 +1011,7 @@ impl<I: Iterator> Iterator for Peekable<I> {
10081011
}
10091012

10101013
#[inline]
1014+
#[rustc_inherit_overflow_checks]
10111015
fn count(self) -> usize {
10121016
(if self.peeked.is_some() { 1 } else { 0 }) + self.iter.count()
10131017
}

src/libcore/num/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ macro_rules! int_impl {
10331033
/// ```
10341034
#[stable(feature = "rust1", since = "1.0.0")]
10351035
#[inline]
1036-
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD.
1036+
#[rustc_inherit_overflow_checks]
10371037
pub fn pow(self, mut exp: u32) -> Self {
10381038
let mut base = self;
10391039
let mut acc = Self::one();
@@ -1075,7 +1075,7 @@ macro_rules! int_impl {
10751075
/// ```
10761076
#[stable(feature = "rust1", since = "1.0.0")]
10771077
#[inline]
1078-
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD.
1078+
#[rustc_inherit_overflow_checks]
10791079
pub fn abs(self) -> Self {
10801080
if self.is_negative() {
10811081
// Note that the #[inline] above means that the overflow
@@ -2061,7 +2061,7 @@ macro_rules! uint_impl {
20612061
/// ```
20622062
#[stable(feature = "rust1", since = "1.0.0")]
20632063
#[inline]
2064-
#[rustc_no_mir] // FIXME #29769 MIR overflow checking is TBD.
2064+
#[rustc_inherit_overflow_checks]
20652065
pub fn pow(self, mut exp: u32) -> Self {
20662066
let mut base = self;
20672067
let mut acc = Self::one();

src/libcore/ops.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ macro_rules! add_impl {
208208
type Output = $t;
209209

210210
#[inline]
211+
#[rustc_inherit_overflow_checks]
211212
fn add(self, other: $t) -> $t { self + other }
212213
}
213214

@@ -261,6 +262,7 @@ macro_rules! sub_impl {
261262
type Output = $t;
262263

263264
#[inline]
265+
#[rustc_inherit_overflow_checks]
264266
fn sub(self, other: $t) -> $t { self - other }
265267
}
266268

@@ -314,6 +316,7 @@ macro_rules! mul_impl {
314316
type Output = $t;
315317

316318
#[inline]
319+
#[rustc_inherit_overflow_checks]
317320
fn mul(self, other: $t) -> $t { self * other }
318321
}
319322

@@ -511,6 +514,7 @@ macro_rules! neg_impl_core {
511514
type Output = $t;
512515

513516
#[inline]
517+
#[rustc_inherit_overflow_checks]
514518
fn neg(self) -> $t { let $id = self; $body }
515519
}
516520

@@ -788,6 +792,7 @@ macro_rules! shl_impl {
788792
type Output = $t;
789793

790794
#[inline]
795+
#[rustc_inherit_overflow_checks]
791796
fn shl(self, other: $f) -> $t {
792797
self << other
793798
}
@@ -859,6 +864,7 @@ macro_rules! shr_impl {
859864
type Output = $t;
860865

861866
#[inline]
867+
#[rustc_inherit_overflow_checks]
862868
fn shr(self, other: $f) -> $t {
863869
self >> other
864870
}
@@ -923,6 +929,7 @@ macro_rules! add_assign_impl {
923929
#[stable(feature = "op_assign_traits", since = "1.8.0")]
924930
impl AddAssign for $t {
925931
#[inline]
932+
#[rustc_inherit_overflow_checks]
926933
fn add_assign(&mut self, other: $t) { *self += other }
927934
}
928935
)+)
@@ -967,6 +974,7 @@ macro_rules! sub_assign_impl {
967974
#[stable(feature = "op_assign_traits", since = "1.8.0")]
968975
impl SubAssign for $t {
969976
#[inline]
977+
#[rustc_inherit_overflow_checks]
970978
fn sub_assign(&mut self, other: $t) { *self -= other }
971979
}
972980
)+)
@@ -1011,6 +1019,7 @@ macro_rules! mul_assign_impl {
10111019
#[stable(feature = "op_assign_traits", since = "1.8.0")]
10121020
impl MulAssign for $t {
10131021
#[inline]
1022+
#[rustc_inherit_overflow_checks]
10141023
fn mul_assign(&mut self, other: $t) { *self *= other }
10151024
}
10161025
)+)
@@ -1275,6 +1284,7 @@ macro_rules! shl_assign_impl {
12751284
#[stable(feature = "op_assign_traits", since = "1.8.0")]
12761285
impl ShlAssign<$f> for $t {
12771286
#[inline]
1287+
#[rustc_inherit_overflow_checks]
12781288
fn shl_assign(&mut self, other: $f) {
12791289
*self <<= other
12801290
}
@@ -1337,6 +1347,7 @@ macro_rules! shr_assign_impl {
13371347
#[stable(feature = "op_assign_traits", since = "1.8.0")]
13381348
impl ShrAssign<$f> for $t {
13391349
#[inline]
1350+
#[rustc_inherit_overflow_checks]
13401351
fn shr_assign(&mut self, other: $f) {
13411352
*self >>= other
13421353
}

0 commit comments

Comments
 (0)