Skip to content

Commit 0399d14

Browse files
committed
Add comment explaining the reversed operands tests
Also, fix the goofy reversed names with something clearer.
1 parent de02a9e commit 0399d14

4 files changed

+60
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
error: this arithmetic operation will overflow
2-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
55
| ^^^^^^^^^ attempt to negate with overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
10-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
12-
LL | const GEN: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate with overflow
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
1414

1515
error: this arithmetic operation will overflow
16-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
1919
| ^^^^^^^^^^^^ attempt to add with overflow
2020

2121
error: this arithmetic operation will overflow
22-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
24-
LL | const DDA: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to add with overflow
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
2626

2727
error: this operation will panic at runtime
28-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
2929
|
3030
LL | const DIV: i32 = (1/0) + T::DIV;
3131
| ^^^^^ attempt to divide by zero
3232
|
3333
= note: `#[deny(unconditional_panic)]` on by default
3434

3535
error: this operation will panic at runtime
36-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
3737
|
38-
LL | const VID: i32 = T::DIV + (1/0);
39-
| ^^^^^ attempt to divide by zero
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
4040

4141
error: this operation will panic at runtime
42-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
4343
|
4444
LL | const OOB: i32 = [1][1] + T::OOB;
4545
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
4646

4747
error: this operation will panic at runtime
48-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
4949
|
50-
LL | const BOO: i32 = T::OOB + [1][1];
51-
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
5252

5353
error: aborting due to 8 previous errors
5454

Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
error: this arithmetic operation will overflow
2-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
55
| ^^^^^^^^^ attempt to negate with overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
10-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
12-
LL | const GEN: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate with overflow
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
1414

1515
error: this arithmetic operation will overflow
16-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
1919
| ^^^^^^^^^^^^ attempt to add with overflow
2020

2121
error: this arithmetic operation will overflow
22-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
24-
LL | const DDA: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to add with overflow
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
2626

2727
error: this operation will panic at runtime
28-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
2929
|
3030
LL | const DIV: i32 = (1/0) + T::DIV;
3131
| ^^^^^ attempt to divide by zero
3232
|
3333
= note: `#[deny(unconditional_panic)]` on by default
3434

3535
error: this operation will panic at runtime
36-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
3737
|
38-
LL | const VID: i32 = T::DIV + (1/0);
39-
| ^^^^^ attempt to divide by zero
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
4040

4141
error: this operation will panic at runtime
42-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
4343
|
4444
LL | const OOB: i32 = [1][1] + T::OOB;
4545
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
4646

4747
error: this operation will panic at runtime
48-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
4949
|
50-
LL | const BOO: i32 = T::OOB + [1][1];
51-
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
5252

5353
error: aborting due to 8 previous errors
5454

Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
error: this arithmetic operation will overflow
2-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:28:22
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
55
| ^^^^^^^^^ attempt to negate with overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
10-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:30:31
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
12-
LL | const GEN: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate with overflow
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
1414

1515
error: this arithmetic operation will overflow
16-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:33:22
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
1919
| ^^^^^^^^^^^^ attempt to add with overflow
2020

2121
error: this arithmetic operation will overflow
22-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:35:32
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
24-
LL | const DDA: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to add with overflow
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
2626

2727
error: this operation will panic at runtime
28-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:38:22
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
2929
|
3030
LL | const DIV: i32 = (1/0) + T::DIV;
3131
| ^^^^^ attempt to divide by zero
3232
|
3333
= note: `#[deny(unconditional_panic)]` on by default
3434

3535
error: this operation will panic at runtime
36-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:40:31
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
3737
|
38-
LL | const VID: i32 = T::DIV + (1/0);
39-
| ^^^^^ attempt to divide by zero
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
4040

4141
error: this operation will panic at runtime
42-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:43:22
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
4343
|
4444
LL | const OOB: i32 = [1][1] + T::OOB;
4545
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
4646

4747
error: this operation will panic at runtime
48-
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:45:31
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
4949
|
50-
LL | const BOO: i32 = T::OOB + [1][1];
51-
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
5252

5353
error: aborting due to 8 previous errors
5454

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,40 @@ use std::i32;
99

1010
pub trait Foo {
1111
const NEG: i32;
12-
const GEN: i32;
12+
const NEG_REV: i32;
1313

1414
const ADD: i32;
15-
const DDA: i32;
15+
const ADD_REV: i32;
1616

1717
const DIV: i32;
18-
const VID: i32;
18+
const DIV_REV: i32;
1919

2020
const OOB: i32;
21-
const BOO: i32;
21+
const OOB_REV: i32;
2222
}
2323

24-
// These constants cannot be evaluated already (they depend on `T::N`), so
25-
// they can just be linted like normal run-time code. But codegen works
26-
// 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).
2728
impl<T: Foo> Foo for Vec<T> {
2829
const NEG: i32 = -i32::MIN + T::NEG;
2930
//~^ ERROR arithmetic operation will overflow
30-
const GEN: i32 = T::NEG + (-i32::MIN);
31+
const NEG_REV: i32 = T::NEG + (-i32::MIN);
3132
//~^ ERROR arithmetic operation will overflow
3233

3334
const ADD: i32 = (i32::MAX+1) + T::ADD;
3435
//~^ ERROR arithmetic operation will overflow
35-
const DDA: i32 = T::ADD + (i32::MAX+1);
36+
const ADD_REV: i32 = T::ADD + (i32::MAX+1);
3637
//~^ ERROR arithmetic operation will overflow
3738

3839
const DIV: i32 = (1/0) + T::DIV;
3940
//~^ ERROR operation will panic
40-
const VID: i32 = T::DIV + (1/0);
41+
const DIV_REV: i32 = T::DIV + (1/0);
4142
//~^ ERROR operation will panic
4243

4344
const OOB: i32 = [1][1] + T::OOB;
4445
//~^ ERROR operation will panic
45-
const BOO: i32 = T::OOB + [1][1];
46+
const OOB_REV: i32 = T::OOB + [1][1];
4647
//~^ ERROR operation will panic
4748
}

0 commit comments

Comments
 (0)