Skip to content

Commit 4382436

Browse files
committed
Make invalid integer operation messages consistent
1 parent 953f33c commit 4382436

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

+30-26
Original file line numberDiff line numberDiff line change
@@ -1279,49 +1279,49 @@ impl<O> AssertKind<O> {
12791279
match self {
12801280
BoundsCheck { ref len, ref index } => write!(
12811281
f,
1282-
"\"index out of bounds: the len is {{}} but the index is {{}}\", {:?}, {:?}",
1282+
"\"index out of bounds: the length is {{}} but the index is {{}}\", {:?}, {:?}",
12831283
len, index
12841284
),
12851285

12861286
OverflowNeg(op) => {
1287-
write!(f, "\"attempt to negate {{}} which would overflow\", {:?}", op)
1287+
write!(f, "\"attempt to negate `{{}}`, which would overflow\", {:?}", op)
12881288
}
1289-
DivisionByZero(op) => write!(f, "\"attempt to divide {{}} by zero\", {:?}", op),
1289+
DivisionByZero(op) => write!(f, "\"attempt to divide `{{}}` by zero\", {:?}", op),
12901290
RemainderByZero(op) => write!(
12911291
f,
1292-
"\"attempt to calculate the remainder of {{}} with a divisor of zero\", {:?}",
1292+
"\"attempt to calculate the remainder of `{{}}` with a divisor of zero\", {:?}",
12931293
op
12941294
),
12951295
Overflow(BinOp::Add, l, r) => write!(
12961296
f,
1297-
"\"attempt to compute `{{}} + {{}}` which would overflow\", {:?}, {:?}",
1297+
"\"attempt to compute `{{}} + {{}}`, which would overflow\", {:?}, {:?}",
12981298
l, r
12991299
),
13001300
Overflow(BinOp::Sub, l, r) => write!(
13011301
f,
1302-
"\"attempt to compute `{{}} - {{}}` which would overflow\", {:?}, {:?}",
1302+
"\"attempt to compute `{{}} - {{}}`, which would overflow\", {:?}, {:?}",
13031303
l, r
13041304
),
13051305
Overflow(BinOp::Mul, l, r) => write!(
13061306
f,
1307-
"\"attempt to compute `{{}} * {{}}` which would overflow\", {:?}, {:?}",
1307+
"\"attempt to compute `{{}} * {{}}`, which would overflow\", {:?}, {:?}",
13081308
l, r
13091309
),
13101310
Overflow(BinOp::Div, l, r) => write!(
13111311
f,
1312-
"\"attempt to compute `{{}} / {{}}` which would overflow\", {:?}, {:?}",
1312+
"\"attempt to compute `{{}} / {{}}`, which would overflow\", {:?}, {:?}",
13131313
l, r
13141314
),
13151315
Overflow(BinOp::Rem, l, r) => write!(
13161316
f,
1317-
"\"attempt to compute the remainder of `{{}} % {{}}` which would overflow\", {:?}, {:?}",
1317+
"\"attempt to compute the remainder of `{{}} % {{}}`, which would overflow\", {:?}, {:?}",
13181318
l, r
13191319
),
13201320
Overflow(BinOp::Shr, _, r) => {
1321-
write!(f, "\"attempt to shift right by {{}} which would overflow\", {:?}", r)
1321+
write!(f, "\"attempt to shift right by `{{}}`, which would overflow\", {:?}", r)
13221322
}
13231323
Overflow(BinOp::Shl, _, r) => {
1324-
write!(f, "\"attempt to shift left by {{}} which would overflow\", {:?}", r)
1324+
write!(f, "\"attempt to shift left by `{{}}`, which would overflow\", {:?}", r)
13251325
}
13261326
_ => write!(f, "\"{}\"", self.description()),
13271327
}
@@ -1332,36 +1332,40 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
13321332
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13331333
use AssertKind::*;
13341334
match self {
1335-
BoundsCheck { ref len, ref index } => {
1336-
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index)
1337-
}
1338-
OverflowNeg(op) => write!(f, "attempt to negate {:#?} which would overflow", op),
1339-
DivisionByZero(op) => write!(f, "attempt to divide {:#?} by zero", op),
1340-
RemainderByZero(op) => {
1341-
write!(f, "attempt to calculate the remainder of {:#?} with a divisor of zero", op)
1342-
}
1335+
BoundsCheck { ref len, ref index } => write!(
1336+
f,
1337+
"index out of bounds: the length is {:?} but the index is {:?}",
1338+
len, index
1339+
),
1340+
OverflowNeg(op) => write!(f, "attempt to negate `{:#?}`, which would overflow", op),
1341+
DivisionByZero(op) => write!(f, "attempt to divide `{:#?}` by zero", op),
1342+
RemainderByZero(op) => write!(
1343+
f,
1344+
"attempt to calculate the remainder of `{:#?}` with a divisor of zero",
1345+
op
1346+
),
13431347
Overflow(BinOp::Add, l, r) => {
1344-
write!(f, "attempt to compute `{:#?} + {:#?}` which would overflow", l, r)
1348+
write!(f, "attempt to compute `{:#?} + {:#?}`, which would overflow", l, r)
13451349
}
13461350
Overflow(BinOp::Sub, l, r) => {
1347-
write!(f, "attempt to compute `{:#?} - {:#?}` which would overflow", l, r)
1351+
write!(f, "attempt to compute `{:#?} - {:#?}`, which would overflow", l, r)
13481352
}
13491353
Overflow(BinOp::Mul, l, r) => {
1350-
write!(f, "attempt to compute `{:#?} * {:#?}` which would overflow", l, r)
1354+
write!(f, "attempt to compute `{:#?} * {:#?}`, which would overflow", l, r)
13511355
}
13521356
Overflow(BinOp::Div, l, r) => {
1353-
write!(f, "attempt to compute `{:#?} / {:#?}` which would overflow", l, r)
1357+
write!(f, "attempt to compute `{:#?} / {:#?}`, which would overflow", l, r)
13541358
}
13551359
Overflow(BinOp::Rem, l, r) => write!(
13561360
f,
1357-
"attempt to compute the remainder of `{:#?} % {:#?}` which would overflow",
1361+
"attempt to compute the remainder of `{:#?} % {:#?}`, which would overflow",
13581362
l, r
13591363
),
13601364
Overflow(BinOp::Shr, _, r) => {
1361-
write!(f, "attempt to shift right by {:#?} which would overflow", r)
1365+
write!(f, "attempt to shift right by `{:#?}`, which would overflow", r)
13621366
}
13631367
Overflow(BinOp::Shl, _, r) => {
1364-
write!(f, "attempt to shift left by {:#?} which would overflow", r)
1368+
write!(f, "attempt to shift left by `{:#?}`, which would overflow", r)
13651369
}
13661370
_ => write!(f, "{}", self.description()),
13671371
}

src/test/ui/array_const_index-0.rs

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+8-8
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

+8-8
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

+8-8
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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)