File tree Expand file tree Collapse file tree 5 files changed +110
-18
lines changed
Expand file tree Collapse file tree 5 files changed +110
-18
lines changed Original file line number Diff line number Diff line change 11error: this arithmetic operation will overflow
2- --> $DIR/issue-69020.rs:15:20
2+ --> $DIR/issue-69020.rs:21:22
33 |
4- LL | const N : i32 = -i32::MIN + T::N ;
5- | ^^^^^^^^^ attempt to negate with overflow
4+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5+ | ^^^^^^^^^ attempt to negate with overflow
66 |
77 = note: `#[deny(overflow)]` on by default
88
9- error: aborting due to previous error
9+ error: this arithmetic operation will overflow
10+ --> $DIR/issue-69020.rs:23:22
11+ |
12+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13+ | ^^^^^^^^^^^^ attempt to add with overflow
14+
15+ error: this operation will panic at runtime
16+ --> $DIR/issue-69020.rs:25:22
17+ |
18+ LL | const DIV: i32 = (1/0) + T::DIV;
19+ | ^^^^^ attempt to divide by zero
20+ |
21+ = note: `#[deny(panic)]` on by default
22+
23+ error: this operation will panic at runtime
24+ --> $DIR/issue-69020.rs:27:22
25+ |
26+ LL | const OOB: i32 = [1][1] + T::OOB;
27+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28+
29+ error: aborting due to 4 previous errors
1030
Original file line number Diff line number Diff line change 11error: this arithmetic operation will overflow
2- --> $DIR/issue-69020.rs:15:20
2+ --> $DIR/issue-69020.rs:21:22
33 |
4- LL | const N : i32 = -i32::MIN + T::N ;
5- | ^^^^^^^^^ attempt to negate with overflow
4+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5+ | ^^^^^^^^^ attempt to negate with overflow
66 |
77 = note: `#[deny(overflow)]` on by default
88
9- error: aborting due to previous error
9+ error: this arithmetic operation will overflow
10+ --> $DIR/issue-69020.rs:23:22
11+ |
12+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13+ | ^^^^^^^^^^^^ attempt to add with overflow
14+
15+ error: this operation will panic at runtime
16+ --> $DIR/issue-69020.rs:25:22
17+ |
18+ LL | const DIV: i32 = (1/0) + T::DIV;
19+ | ^^^^^ attempt to divide by zero
20+ |
21+ = note: `#[deny(panic)]` on by default
22+
23+ error: this operation will panic at runtime
24+ --> $DIR/issue-69020.rs:27:22
25+ |
26+ LL | const OOB: i32 = [1][1] + T::OOB;
27+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28+
29+ error: aborting due to 4 previous errors
1030
Original file line number Diff line number Diff line change 11error: this arithmetic operation will overflow
2- --> $DIR/issue-69020.rs:15:20
2+ --> $DIR/issue-69020.rs:21:22
33 |
4- LL | const N : i32 = -i32::MIN + T::N ;
5- | ^^^^^^^^^ attempt to negate with overflow
4+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5+ | ^^^^^^^^^ attempt to negate with overflow
66 |
77 = note: `#[deny(overflow)]` on by default
88
9- error: aborting due to previous error
9+ error: this arithmetic operation will overflow
10+ --> $DIR/issue-69020.rs:23:22
11+ |
12+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13+ | ^^^^^^^^^^^^ attempt to add with overflow
14+
15+ error: this operation will panic at runtime
16+ --> $DIR/issue-69020.rs:25:22
17+ |
18+ LL | const DIV: i32 = (1/0) + T::DIV;
19+ | ^^^^^ attempt to divide by zero
20+ |
21+ = note: `#[deny(panic)]` on by default
22+
23+ error: this operation will panic at runtime
24+ --> $DIR/issue-69020.rs:27:22
25+ |
26+ LL | const OOB: i32 = [1][1] + T::OOB;
27+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28+
29+ error: aborting due to 4 previous errors
1030
Original file line number Diff line number Diff line change 11error: this arithmetic operation will overflow
2- --> $DIR/issue-69020.rs:15:20
2+ --> $DIR/issue-69020.rs:21:22
33 |
4- LL | const N : i32 = -i32::MIN + T::N ;
5- | ^^^^^^^^^ attempt to negate with overflow
4+ LL | const NEG : i32 = -i32::MIN + T::NEG ;
5+ | ^^^^^^^^^ attempt to negate with overflow
66 |
77 = note: `#[deny(overflow)]` on by default
88
9- error: aborting due to previous error
9+ error: this arithmetic operation will overflow
10+ --> $DIR/issue-69020.rs:23:22
11+ |
12+ LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
13+ | ^^^^^^^^^^^^ attempt to add with overflow
14+
15+ error: this operation will panic at runtime
16+ --> $DIR/issue-69020.rs:25:22
17+ |
18+ LL | const DIV: i32 = (1/0) + T::DIV;
19+ | ^^^^^ attempt to divide by zero
20+ |
21+ = note: `#[deny(panic)]` on by default
22+
23+ error: this operation will panic at runtime
24+ --> $DIR/issue-69020.rs:27:22
25+ |
26+ LL | const OOB: i32 = [1][1] + T::OOB;
27+ | ^^^^^^ index out of bounds: the len is 1 but the index is 1
28+
29+ error: aborting due to 4 previous errors
1030
Original file line number Diff line number Diff line change 88use std:: i32;
99
1010pub trait Foo {
11- const N : i32 ;
11+ const NEG : i32 ;
12+ const ADD : i32 ;
13+ const DIV : i32 ;
14+ const OOB : i32 ;
1215}
1316
17+ // These constants cannot be evaluated already (they depend on `T::N`), so
18+ // they can just be linted like normal run-time code. But codegen works
19+ // a bit different in const context, so this test makes sure that we still catch overflow.
1420impl < T : Foo > Foo for Vec < T > {
15- const N : i32 = -i32:: MIN + T :: N ;
21+ const NEG : i32 = -i32:: MIN + T :: NEG ;
1622 //~^ ERROR arithmetic operation will overflow
23+ const ADD : i32 = ( i32:: MAX +1 ) + T :: ADD ;
24+ //~^ ERROR arithmetic operation will overflow
25+ const DIV : i32 = ( 1 /0 ) + T :: DIV ;
26+ //~^ ERROR operation will panic
27+ const OOB : i32 = [ 1 ] [ 1 ] + T :: OOB ;
28+ //~^ ERROR operation will panic
1729}
You can’t perform that action at this time.
0 commit comments