Skip to content

Commit 8eb42ba

Browse files
committed
Make invalid integer operation messages consistent
1 parent 6f9a8a7 commit 8eb42ba

File tree

71 files changed

+323
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+323
-319
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,49 +1300,49 @@ impl<O> AssertKind<O> {
13001300
match self {
13011301
BoundsCheck { ref len, ref index } => write!(
13021302
f,
1303-
"\"index out of bounds: the len is {{}} but the index is {{}}\", {:?}, {:?}",
1303+
"\"index out of bounds: the length is {{}} but the index is {{}}\", {:?}, {:?}",
13041304
len, index
13051305
),
13061306

13071307
OverflowNeg(op) => {
1308-
write!(f, "\"attempt to negate {{}} which would overflow\", {:?}", op)
1308+
write!(f, "\"attempt to negate `{{}}`, which would overflow\", {:?}", op)
13091309
}
1310-
DivisionByZero(op) => write!(f, "\"attempt to divide {{}} by zero\", {:?}", op),
1310+
DivisionByZero(op) => write!(f, "\"attempt to divide `{{}}` by zero\", {:?}", op),
13111311
RemainderByZero(op) => write!(
13121312
f,
1313-
"\"attempt to calculate the remainder of {{}} with a divisor of zero\", {:?}",
1313+
"\"attempt to calculate the remainder of `{{}}` with a divisor of zero\", {:?}",
13141314
op
13151315
),
13161316
Overflow(BinOp::Add, l, r) => write!(
13171317
f,
1318-
"\"attempt to compute `{{}} + {{}}` which would overflow\", {:?}, {:?}",
1318+
"\"attempt to compute `{{}} + {{}}`, which would overflow\", {:?}, {:?}",
13191319
l, r
13201320
),
13211321
Overflow(BinOp::Sub, l, r) => write!(
13221322
f,
1323-
"\"attempt to compute `{{}} - {{}}` which would overflow\", {:?}, {:?}",
1323+
"\"attempt to compute `{{}} - {{}}`, which would overflow\", {:?}, {:?}",
13241324
l, r
13251325
),
13261326
Overflow(BinOp::Mul, l, r) => write!(
13271327
f,
1328-
"\"attempt to compute `{{}} * {{}}` which would overflow\", {:?}, {:?}",
1328+
"\"attempt to compute `{{}} * {{}}`, which would overflow\", {:?}, {:?}",
13291329
l, r
13301330
),
13311331
Overflow(BinOp::Div, l, r) => write!(
13321332
f,
1333-
"\"attempt to compute `{{}} / {{}}` which would overflow\", {:?}, {:?}",
1333+
"\"attempt to compute `{{}} / {{}}`, which would overflow\", {:?}, {:?}",
13341334
l, r
13351335
),
13361336
Overflow(BinOp::Rem, l, r) => write!(
13371337
f,
1338-
"\"attempt to compute the remainder of `{{}} % {{}}` which would overflow\", {:?}, {:?}",
1338+
"\"attempt to compute the remainder of `{{}} % {{}}`, which would overflow\", {:?}, {:?}",
13391339
l, r
13401340
),
13411341
Overflow(BinOp::Shr, _, r) => {
1342-
write!(f, "\"attempt to shift right by {{}} which would overflow\", {:?}", r)
1342+
write!(f, "\"attempt to shift right by `{{}}`, which would overflow\", {:?}", r)
13431343
}
13441344
Overflow(BinOp::Shl, _, r) => {
1345-
write!(f, "\"attempt to shift left by {{}} which would overflow\", {:?}", r)
1345+
write!(f, "\"attempt to shift left by `{{}}`, which would overflow\", {:?}", r)
13461346
}
13471347
_ => write!(f, "\"{}\"", self.description()),
13481348
}
@@ -1353,36 +1353,40 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
13531353
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13541354
use AssertKind::*;
13551355
match self {
1356-
BoundsCheck { ref len, ref index } => {
1357-
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index)
1358-
}
1359-
OverflowNeg(op) => write!(f, "attempt to negate {:#?} which would overflow", op),
1360-
DivisionByZero(op) => write!(f, "attempt to divide {:#?} by zero", op),
1361-
RemainderByZero(op) => {
1362-
write!(f, "attempt to calculate the remainder of {:#?} with a divisor of zero", op)
1363-
}
1356+
BoundsCheck { ref len, ref index } => write!(
1357+
f,
1358+
"index out of bounds: the length is {:?} but the index is {:?}",
1359+
len, index
1360+
),
1361+
OverflowNeg(op) => write!(f, "attempt to negate `{:#?}`, which would overflow", op),
1362+
DivisionByZero(op) => write!(f, "attempt to divide `{:#?}` by zero", op),
1363+
RemainderByZero(op) => write!(
1364+
f,
1365+
"attempt to calculate the remainder of `{:#?}` with a divisor of zero",
1366+
op
1367+
),
13641368
Overflow(BinOp::Add, l, r) => {
1365-
write!(f, "attempt to compute `{:#?} + {:#?}` which would overflow", l, r)
1369+
write!(f, "attempt to compute `{:#?} + {:#?}`, which would overflow", l, r)
13661370
}
13671371
Overflow(BinOp::Sub, l, r) => {
1368-
write!(f, "attempt to compute `{:#?} - {:#?}` which would overflow", l, r)
1372+
write!(f, "attempt to compute `{:#?} - {:#?}`, which would overflow", l, r)
13691373
}
13701374
Overflow(BinOp::Mul, l, r) => {
1371-
write!(f, "attempt to compute `{:#?} * {:#?}` which would overflow", l, r)
1375+
write!(f, "attempt to compute `{:#?} * {:#?}`, which would overflow", l, r)
13721376
}
13731377
Overflow(BinOp::Div, l, r) => {
1374-
write!(f, "attempt to compute `{:#?} / {:#?}` which would overflow", l, r)
1378+
write!(f, "attempt to compute `{:#?} / {:#?}`, which would overflow", l, r)
13751379
}
13761380
Overflow(BinOp::Rem, l, r) => write!(
13771381
f,
1378-
"attempt to compute the remainder of `{:#?} % {:#?}` which would overflow",
1382+
"attempt to compute the remainder of `{:#?} % {:#?}`, which would overflow",
13791383
l, r
13801384
),
13811385
Overflow(BinOp::Shr, _, r) => {
1382-
write!(f, "attempt to shift right by {:#?} which would overflow", r)
1386+
write!(f, "attempt to shift right by `{:#?}`, which would overflow", r)
13831387
}
13841388
Overflow(BinOp::Shl, _, r) => {
1385-
write!(f, "attempt to shift left by {:#?} which would overflow", r)
1389+
write!(f, "attempt to shift left by `{:#?}`, which would overflow", r)
13861390
}
13871391
_ => write!(f, "{}", self.description()),
13881392
}

src/test/ui/array_const_index-0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const A: &'static [i32] = &[];
22
const B: i32 = (&A)[1];
3-
//~^ index out of bounds: the len is 0 but the index is 1
3+
//~^ index out of bounds: the length is 0 but the index is 1
44
//~| ERROR any use of this value will cause an error
55

66
fn main() {

src/test/ui/array_const_index-0.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
44
LL | const B: i32 = (&A)[1];
55
| ---------------^^^^^^^-
66
| |
7-
| index out of bounds: the len is 0 but the index is 1
7+
| index out of bounds: the length is 0 but the index is 1
88
|
99
= note: `#[deny(const_err)]` on by default
1010

src/test/ui/array_const_index-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const A: [i32; 0] = [];
22
const B: i32 = A[1];
3-
//~^ index out of bounds: the len is 0 but the index is 1
3+
//~^ index out of bounds: the length is 0 but the index is 1
44
//~| ERROR any use of this value will cause an error
55

66
fn main() {

src/test/ui/array_const_index-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
44
LL | const B: i32 = A[1];
55
| ---------------^^^^-
66
| |
7-
| index out of bounds: the len is 0 but the index is 1
7+
| index out of bounds: the length is 0 but the index is 1
88
|
99
= note: `#[deny(const_err)]` on by default
1010

src/test/ui/associated-const/defaults-not-assumed-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
44
LL | const B: u8 = Self::A + 1;
55
| --------------^^^^^^^^^^^-
66
| |
7-
| attempt to compute `u8::MAX + 1_u8` which would overflow
7+
| attempt to compute `u8::MAX + 1_u8`, which would overflow
88
|
99
= note: `#[deny(const_err)]` on by default
1010

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,53 @@ error: this arithmetic operation will overflow
22
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
5-
| ^^^^^^^^^ attempt to negate i32::MIN which would overflow
5+
| ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
1010
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
1212
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow
13+
| ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
1414

1515
error: this arithmetic operation will overflow
1616
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
19+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2020

2121
error: this arithmetic operation will overflow
2222
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
2424
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
25+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2626

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

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

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

4747
error: this operation will panic at runtime
4848
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
4949
|
5050
LL | const OOB_REV: i32 = T::OOB + [1][1];
51-
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
51+
| ^^^^^^ index out of bounds: the length 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.opt.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,53 @@ error: this arithmetic operation will overflow
22
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
5-
| ^^^^^^^^^ attempt to negate i32::MIN which would overflow
5+
| ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
1010
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
1212
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow
13+
| ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
1414

1515
error: this arithmetic operation will overflow
1616
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
19+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2020

2121
error: this arithmetic operation will overflow
2222
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
2424
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
25+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2626

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

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

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

4747
error: this operation will panic at runtime
4848
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
4949
|
5050
LL | const OOB_REV: i32 = T::OOB + [1][1];
51-
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
51+
| ^^^^^^ index out of bounds: the length 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.opt_with_overflow_checks.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,53 @@ error: this arithmetic operation will overflow
22
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
33
|
44
LL | const NEG: i32 = -i32::MIN + T::NEG;
5-
| ^^^^^^^^^ attempt to negate i32::MIN which would overflow
5+
| ^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
66
|
77
= note: `#[deny(arithmetic_overflow)]` on by default
88

99
error: this arithmetic operation will overflow
1010
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
1111
|
1212
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13-
| ^^^^^^^^^^^ attempt to negate i32::MIN which would overflow
13+
| ^^^^^^^^^^^ attempt to negate `i32::MIN`, which would overflow
1414

1515
error: this arithmetic operation will overflow
1616
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
1717
|
1818
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
19+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2020

2121
error: this arithmetic operation will overflow
2222
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
2323
|
2424
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25-
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32` which would overflow
25+
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
2626

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

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

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

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

5353
error: aborting due to 8 previous errors
5454

src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/simple_fail.rs:7:33
33
|
44
LL | type Arr<const N: usize> = [u8; N - 1];
5-
| ^^^^^ attempt to compute `0_usize - 1_usize` which would overflow
5+
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
66

77
error: aborting due to previous error
88

src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: this operation will panic at runtime
22
--> $DIR/ice-assert-fail-div-by-zero.rs:11:5
33
|
44
LL | f.0 / 0;
5-
| ^^^^^^^ attempt to divide _ by zero
5+
| ^^^^^^^ attempt to divide `_` by zero
66
|
77
note: the lint level is defined here
88
--> $DIR/ice-assert-fail-div-by-zero.rs:5:9

src/test/ui/consts/array-literal-index-oob.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: this operation will panic at runtime
22
--> $DIR/array-literal-index-oob.rs:7:8
33
|
44
LL | &{ [1, 2, 3][4] };
5-
| ^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 4
5+
| ^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 4
66
|
77
note: the lint level is defined here
88
--> $DIR/array-literal-index-oob.rs:4:20

src/test/ui/consts/assoc_const_generic_impl.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: any use of this value will cause an error
44
LL | const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()];
55
| -----------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
66
| |
7-
| index out of bounds: the len is 1 but the index is 4
7+
| index out of bounds: the length is 1 but the index is 4
88
|
99
note: the lint level is defined here
1010
--> $DIR/assoc_const_generic_impl.rs:3:9

src/test/ui/consts/const-array-oob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BAR: usize = FOO[5]; // no error, because the error below occurs before re
55

66
const BLUB: [u32; FOO[4]] = [5, 6];
77
//~^ ERROR evaluation of constant value failed [E0080]
8-
//~| index out of bounds: the len is 3 but the index is 4
8+
//~| index out of bounds: the length is 3 but the index is 4
99

1010
fn main() {
1111
let _ = BAR;

src/test/ui/consts/const-array-oob.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/const-array-oob.rs:6:19
33
|
44
LL | const BLUB: [u32; FOO[4]] = [5, 6];
5-
| ^^^^^^ index out of bounds: the len is 3 but the index is 4
5+
| ^^^^^^ index out of bounds: the length is 3 but the index is 4
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)