Skip to content

Commit ea28134

Browse files
authored
Rollup merge of #70696 - jumbatm:extend-issue-69020-test, r=RalfJung
Extend #69020 test to include reversed operand order. Make sure we still emit if a lint if the generic argument comes first. See #70566 (comment). r? @RalfJung
2 parents 424c793 + 0399d14 commit ea28134

7 files changed

+184
-93
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+

src/test/ui/consts/issue-69020.rs renamed to src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,40 @@ use std::i32;
99

1010
pub trait Foo {
1111
const NEG: i32;
12+
const NEG_REV: i32;
13+
1214
const ADD: i32;
15+
const ADD_REV: i32;
16+
1317
const DIV: i32;
18+
const DIV_REV: i32;
19+
1420
const OOB: i32;
21+
const OOB_REV: i32;
1522
}
1623

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.
24+
// These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
25+
// like normal run-time code. But codegen works a bit different in const context, so this test
26+
// makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
27+
// operands (so that the generic operand comes first).
2028
impl<T: Foo> Foo for Vec<T> {
2129
const NEG: i32 = -i32::MIN + T::NEG;
2230
//~^ ERROR arithmetic operation will overflow
31+
const NEG_REV: i32 = T::NEG + (-i32::MIN);
32+
//~^ ERROR arithmetic operation will overflow
33+
2334
const ADD: i32 = (i32::MAX+1) + T::ADD;
2435
//~^ ERROR arithmetic operation will overflow
36+
const ADD_REV: i32 = T::ADD + (i32::MAX+1);
37+
//~^ ERROR arithmetic operation will overflow
38+
2539
const DIV: i32 = (1/0) + T::DIV;
2640
//~^ ERROR operation will panic
41+
const DIV_REV: i32 = T::DIV + (1/0);
42+
//~^ ERROR operation will panic
43+
2744
const OOB: i32 = [1][1] + T::OOB;
2845
//~^ ERROR operation will panic
46+
const OOB_REV: i32 = T::OOB + [1][1];
47+
//~^ ERROR operation will panic
2948
}

src/test/ui/consts/issue-69020.noopt.stderr

-30
This file was deleted.

src/test/ui/consts/issue-69020.opt.stderr

-30
This file was deleted.

src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr

-30
This file was deleted.

0 commit comments

Comments
 (0)