Skip to content

Commit 415218f

Browse files
committed
expand assoc-const test a bit, just to be sure
1 parent 2107e73 commit 415218f

5 files changed

+110
-18
lines changed
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
error: 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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
error: 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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
error: 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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
error: 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

src/test/ui/consts/issue-69020.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@
88
use std::i32;
99

1010
pub 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.
1420
impl<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
}

0 commit comments

Comments
 (0)