Skip to content

Commit 8d54ea3

Browse files
committed
Fallout from changes for overflow-checking during constant evaluation.
1 parent 6808e41 commit 8d54ea3

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

src/libcoretest/num/uint_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod tests {
2020
fn test_overflows() {
2121
assert!(MAX > 0);
2222
assert!(MIN <= 0);
23-
assert!(MIN + MAX + 1 == 0);
23+
assert!((MIN + MAX).wrapping_add(1) == 0);
2424
}
2525

2626
#[test]

src/libstd/old_io/extensions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ mod bench {
519519
({
520520
use super::u64_from_be_bytes;
521521

522-
let data = (0..$stride*100+$start_index).collect::<Vec<_>>();
522+
let len = $stride.wrapping_mul(100).wrapping_add($start_index);
523+
let data = (0..len).collect::<Vec<_>>();
523524
let mut sum = 0;
524525
$b.iter(|| {
525526
let mut i = $start_index;

src/test/compile-fail/non-constant-enum-for-vec-repeat.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Note: This test is checking that we forbid a coding pattern that
12+
// Issue #5873 explicitly wants to allow.
13+
1114
enum State { ST_NULL, ST_WHITESPACE }
1215

1316
fn main() {
1417
[State::ST_NULL; (State::ST_WHITESPACE as usize)];
15-
//~^ ERROR expected constant integer for repeat count, found non-constant expression
18+
//~^ ERROR expected constant integer for repeat count, but non-constant path
1619
}

src/test/compile-fail/non-constant-expr-for-vec-repeat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
fn main() {
1414
fn bar(n: usize) {
15-
let _x = [0; n]; //~ ERROR expected constant integer for repeat count, found variable
15+
let _x = [0; n];
16+
//~^ ERROR expected constant integer for repeat count, found variable
1617
}
1718
}

src/test/run-pass/big-literals.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
// pretty-expanded FIXME #23616
1212

13+
#![feature(core)]
14+
15+
// Catch mistakes in the overflowing literals lint.
16+
#![deny(overflowing_literals)]
17+
1318
pub fn main() {
1419
assert_eq!(0xffffffff, (-1 as u32));
1520
assert_eq!(4294967295, (-1 as u32));
1621
assert_eq!(0xffffffffffffffff, (-1 as u64));
1722
assert_eq!(18446744073709551615, (-1 as u64));
1823

19-
assert_eq!(-2147483648 - 1, 2147483647);
24+
assert_eq!((-2147483648).wrapping_sub(1), 2147483647);
2025
}

src/test/run-pass/small-enum-range-edge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static CLs: Es = Es::Ls;
2929
static CHs: Es = Es::Hs;
3030

3131
pub fn main() {
32-
assert_eq!((Eu::Hu as u8) + 1, Eu::Lu as u8);
33-
assert_eq!((Es::Hs as i8) + 1, Es::Ls as i8);
32+
assert_eq!((Eu::Hu as u8).wrapping_add(1), Eu::Lu as u8);
33+
assert_eq!((Es::Hs as i8).wrapping_add(1), Es::Ls as i8);
3434
assert_eq!(CLu as u8, Eu::Lu as u8);
3535
assert_eq!(CHu as u8, Eu::Hu as u8);
3636
assert_eq!(CLs as i8, Es::Ls as i8);

0 commit comments

Comments
 (0)