Skip to content

Commit a9b16c6

Browse files
committed
Improve error and help messages
1 parent d00ca11 commit a9b16c6

10 files changed

+48
-48
lines changed

compiler/rustc_lint/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn report_bin_hex_error(
225225
(t.name_str(), actually.to_string())
226226
}
227227
};
228-
let mut err = lint.build(&format!("literal out of range for {}", t));
228+
let mut err = lint.build(&format!("literal out of range for `{}`", t));
229229
err.note(&format!(
230230
"the literal `{}` (decimal `{}`) does not fit into \
231231
the type `{}` and will become `{}{}`",
@@ -238,12 +238,12 @@ fn report_bin_hex_error(
238238
let (sans_suffix, _) = repr_str.split_at(pos);
239239
err.span_suggestion(
240240
expr.span,
241-
&format!("consider using `{}` instead", sugg_ty),
241+
&format!("consider using the type `{}` instead", sugg_ty),
242242
format!("{}{}", sans_suffix, sugg_ty),
243243
Applicability::MachineApplicable,
244244
);
245245
} else {
246-
err.help(&format!("consider using `{}` instead", sugg_ty));
246+
err.help(&format!("consider using the type `{}` instead", sugg_ty));
247247
}
248248
}
249249
err.emit();
@@ -345,7 +345,7 @@ fn lint_int_literal<'tcx>(
345345
if let Some(sugg_ty) =
346346
get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative)
347347
{
348-
err.help(&format!("consider using `{}` instead", sugg_ty));
348+
err.help(&format!("consider using the type `{}` instead", sugg_ty));
349349
}
350350
err.emit();
351351
});

src/test/ui/enum/enum-discrim-too-small2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(overflowing_literals)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212
= note: the literal `223` does not fit into the type `i8` whose range is `-128..=127`
13-
= help: consider using `u8` instead
13+
= help: consider using the type `u8` instead
1414

1515
error: literal out of range for `i16`
1616
--> $DIR/enum-discrim-too-small2.rs:15:12
@@ -19,7 +19,7 @@ LL | Ci16 = 55555,
1919
| ^^^^^
2020
|
2121
= note: the literal `55555` does not fit into the type `i16` whose range is `-32768..=32767`
22-
= help: consider using `u16` instead
22+
= help: consider using the type `u16` instead
2323

2424
error: literal out of range for `i32`
2525
--> $DIR/enum-discrim-too-small2.rs:22:12
@@ -28,7 +28,7 @@ LL | Ci32 = 3_000_000_000,
2828
| ^^^^^^^^^^^^^
2929
|
3030
= note: the literal `3_000_000_000` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
31-
= help: consider using `u32` instead
31+
= help: consider using the type `u32` instead
3232

3333
error: literal out of range for `i64`
3434
--> $DIR/enum-discrim-too-small2.rs:29:12
@@ -37,7 +37,7 @@ LL | Ci64 = 9223372036854775809,
3737
| ^^^^^^^^^^^^^^^^^^^
3838
|
3939
= note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
40-
= help: consider using `u64` instead
40+
= help: consider using the type `u64` instead
4141

4242
error: aborting due to 4 previous errors
4343

src/test/ui/issues/issue-79744.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
let elem = 6i8;
33
let e2 = 230;
44
//~^ ERROR literal out of range for `i8`
5-
//~| HELP consider using `u8` instead
5+
//~| HELP consider using the type `u8` instead
66

77
let mut vec = Vec::new();
88

src/test/ui/issues/issue-79744.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let e2 = 230;
66
|
77
= note: `#[deny(overflowing_literals)]` on by default
88
= note: the literal `230` does not fit into the type `i8` whose range is `-128..=127`
9-
= help: consider using `u8` instead
9+
= help: consider using the type `u8` instead
1010

1111
error: aborting due to previous error
1212

src/test/ui/lint/lint-type-limits2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ note: the lint level is defined here
1818
LL | #![warn(overflowing_literals)]
1919
| ^^^^^^^^^^^^^^^^^^^^
2020
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
21-
= help: consider using `u8` instead
21+
= help: consider using the type `u8` instead
2222

2323
error: aborting due to previous error; 1 warning emitted
2424

src/test/ui/lint/lint-type-limits3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ note: the lint level is defined here
1818
LL | #![warn(overflowing_literals)]
1919
| ^^^^^^^^^^^^^^^^^^^^
2020
= note: the literal `200` does not fit into the type `i8` whose range is `-128..=127`
21-
= help: consider using `u8` instead
21+
= help: consider using the type `u8` instead
2222

2323
error: aborting due to previous error; 1 warning emitted
2424

src/test/ui/lint/lint-type-overflow.stderr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LL | let x1: i8 = 128;
2626
| ^^^
2727
|
2828
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
29-
= help: consider using `u8` instead
29+
= help: consider using the type `u8` instead
3030

3131
error: literal out of range for `i8`
3232
--> $DIR/lint-type-overflow.rs:18:19
@@ -35,7 +35,7 @@ LL | let x3: i8 = -129;
3535
| ^^^
3636
|
3737
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
38-
= help: consider using `i16` instead
38+
= help: consider using the type `i16` instead
3939

4040
error: literal out of range for `i8`
4141
--> $DIR/lint-type-overflow.rs:19:19
@@ -44,7 +44,7 @@ LL | let x3: i8 = -(129);
4444
| ^^^^^
4545
|
4646
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
47-
= help: consider using `i16` instead
47+
= help: consider using the type `i16` instead
4848

4949
error: literal out of range for `i8`
5050
--> $DIR/lint-type-overflow.rs:20:20
@@ -53,7 +53,7 @@ LL | let x3: i8 = -{129};
5353
| ^^^
5454
|
5555
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
56-
= help: consider using `u8` instead
56+
= help: consider using the type `u8` instead
5757

5858
error: literal out of range for `i8`
5959
--> $DIR/lint-type-overflow.rs:22:10
@@ -62,7 +62,7 @@ LL | test(1000);
6262
| ^^^^
6363
|
6464
= note: the literal `1000` does not fit into the type `i8` whose range is `-128..=127`
65-
= help: consider using `i16` instead
65+
= help: consider using the type `i16` instead
6666

6767
error: literal out of range for `i8`
6868
--> $DIR/lint-type-overflow.rs:24:13
@@ -71,7 +71,7 @@ LL | let x = 128_i8;
7171
| ^^^^^^
7272
|
7373
= note: the literal `128_i8` does not fit into the type `i8` whose range is `-128..=127`
74-
= help: consider using `u8` instead
74+
= help: consider using the type `u8` instead
7575

7676
error: literal out of range for `i8`
7777
--> $DIR/lint-type-overflow.rs:28:14
@@ -80,7 +80,7 @@ LL | let x = -129_i8;
8080
| ^^^^^^
8181
|
8282
= note: the literal `129_i8` does not fit into the type `i8` whose range is `-128..=127`
83-
= help: consider using `i16` instead
83+
= help: consider using the type `i16` instead
8484

8585
error: literal out of range for `i32`
8686
--> $DIR/lint-type-overflow.rs:32:18
@@ -89,7 +89,7 @@ LL | let x: i32 = 2147483648;
8989
| ^^^^^^^^^^
9090
|
9191
= note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
92-
= help: consider using `u32` instead
92+
= help: consider using the type `u32` instead
9393

9494
error: literal out of range for `i32`
9595
--> $DIR/lint-type-overflow.rs:33:13
@@ -98,7 +98,7 @@ LL | let x = 2147483648_i32;
9898
| ^^^^^^^^^^^^^^
9999
|
100100
= note: the literal `2147483648_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
101-
= help: consider using `u32` instead
101+
= help: consider using the type `u32` instead
102102

103103
error: literal out of range for `i32`
104104
--> $DIR/lint-type-overflow.rs:36:19
@@ -107,7 +107,7 @@ LL | let x: i32 = -2147483649;
107107
| ^^^^^^^^^^
108108
|
109109
= note: the literal `2147483649` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
110-
= help: consider using `i64` instead
110+
= help: consider using the type `i64` instead
111111

112112
error: literal out of range for `i32`
113113
--> $DIR/lint-type-overflow.rs:37:14
@@ -116,7 +116,7 @@ LL | let x = -2147483649_i32;
116116
| ^^^^^^^^^^^^^^
117117
|
118118
= note: the literal `2147483649_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
119-
= help: consider using `i64` instead
119+
= help: consider using the type `i64` instead
120120

121121
error: literal out of range for `i32`
122122
--> $DIR/lint-type-overflow.rs:38:13
@@ -125,7 +125,7 @@ LL | let x = 2147483648;
125125
| ^^^^^^^^^^
126126
|
127127
= note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
128-
= help: consider using `u32` instead
128+
= help: consider using the type `u32` instead
129129

130130
error: literal out of range for `i64`
131131
--> $DIR/lint-type-overflow.rs:40:13
@@ -134,7 +134,7 @@ LL | let x = 9223372036854775808_i64;
134134
| ^^^^^^^^^^^^^^^^^^^^^^^
135135
|
136136
= note: the literal `9223372036854775808_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
137-
= help: consider using `u64` instead
137+
= help: consider using the type `u64` instead
138138

139139
error: literal out of range for `i64`
140140
--> $DIR/lint-type-overflow.rs:42:13
@@ -143,7 +143,7 @@ LL | let x = 18446744073709551615_i64;
143143
| ^^^^^^^^^^^^^^^^^^^^^^^^
144144
|
145145
= note: the literal `18446744073709551615_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
146-
= help: consider using `u64` instead
146+
= help: consider using the type `u64` instead
147147

148148
error: literal out of range for `i64`
149149
--> $DIR/lint-type-overflow.rs:43:19
@@ -152,7 +152,7 @@ LL | let x: i64 = -9223372036854775809;
152152
| ^^^^^^^^^^^^^^^^^^^
153153
|
154154
= note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
155-
= help: consider using `i128` instead
155+
= help: consider using the type `i128` instead
156156

157157
error: literal out of range for `i64`
158158
--> $DIR/lint-type-overflow.rs:44:14
@@ -161,7 +161,7 @@ LL | let x = -9223372036854775809_i64;
161161
| ^^^^^^^^^^^^^^^^^^^^^^^
162162
|
163163
= note: the literal `9223372036854775809_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
164-
= help: consider using `i128` instead
164+
= help: consider using the type `i128` instead
165165

166166
error: aborting due to 18 previous errors
167167

src/test/ui/lint/lint-type-overflow2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(overflowing_literals)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
13-
= help: consider using `u8` instead
13+
= help: consider using the type `u8` instead
1414

1515
error: literal out of range for `f32`
1616
--> $DIR/lint-type-overflow2.rs:9:14

src/test/ui/lint/type-overflow.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ fn main() {
77
let ok = 0b1000_0001; // should be ok -> i32
88
let ok = 0b0111_1111i8; // should be ok -> 127i8
99

10-
let fail = 0b1000_0001i8; //~WARNING literal out of range for i8
10+
let fail = 0b1000_0001i8; //~WARNING literal out of range for `i8`
1111

12-
let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for i64
12+
let fail = 0x8000_0000_0000_0000i64; //~WARNING literal out of range for `i64`
1313

14-
let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for u32
14+
let fail = 0x1_FFFF_FFFFu32; //~WARNING literal out of range for `u32`
1515

1616
let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
17-
//~^ WARNING literal out of range for i128
17+
//~^ WARNING literal out of range for `i128`
1818

19-
let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for i32
19+
let fail = 0x8FFF_FFFF_FFFF_FFFE; //~WARNING literal out of range for `i32`
2020

21-
let fail = -0b1111_1111i8; //~WARNING literal out of range for i8
21+
let fail = -0b1111_1111i8; //~WARNING literal out of range for `i8`
2222
}

src/test/ui/lint/type-overflow.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,55 @@ note: the lint level is defined here
1010
LL | #![warn(overflowing_literals)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212
= note: the literal `255i8` does not fit into the type `i8` whose range is `-128..=127`
13-
= help: consider using `u8` instead
13+
= help: consider using the type `u8` instead
1414

15-
warning: literal out of range for i8
15+
warning: literal out of range for `i8`
1616
--> $DIR/type-overflow.rs:10:16
1717
|
1818
LL | let fail = 0b1000_0001i8;
19-
| ^^^^^^^^^^^^^ help: consider using `u8` instead: `0b1000_0001u8`
19+
| ^^^^^^^^^^^^^ help: consider using the type `u8` instead: `0b1000_0001u8`
2020
|
2121
= note: the literal `0b1000_0001i8` (decimal `129`) does not fit into the type `i8` and will become `-127i8`
2222

23-
warning: literal out of range for i64
23+
warning: literal out of range for `i64`
2424
--> $DIR/type-overflow.rs:12:16
2525
|
2626
LL | let fail = 0x8000_0000_0000_0000i64;
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x8000_0000_0000_0000u64`
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x8000_0000_0000_0000u64`
2828
|
2929
= note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into the type `i64` and will become `-9223372036854775808i64`
3030

31-
warning: literal out of range for u32
31+
warning: literal out of range for `u32`
3232
--> $DIR/type-overflow.rs:14:16
3333
|
3434
LL | let fail = 0x1_FFFF_FFFFu32;
35-
| ^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0x1_FFFF_FFFFu64`
35+
| ^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x1_FFFF_FFFFu64`
3636
|
3737
= note: the literal `0x1_FFFF_FFFFu32` (decimal `8589934591`) does not fit into the type `u32` and will become `4294967295u32`
3838

39-
warning: literal out of range for i128
39+
warning: literal out of range for `i128`
4040
--> $DIR/type-overflow.rs:16:22
4141
|
4242
LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444
|
4545
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into the type `i128` and will become `-170141183460469231731687303715884105728i128`
46-
= help: consider using `u128` instead
46+
= help: consider using the type `u128` instead
4747

48-
warning: literal out of range for i32
48+
warning: literal out of range for `i32`
4949
--> $DIR/type-overflow.rs:19:16
5050
|
5151
LL | let fail = 0x8FFF_FFFF_FFFF_FFFE;
5252
| ^^^^^^^^^^^^^^^^^^^^^
5353
|
5454
= note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into the type `i32` and will become `-2i32`
55-
= help: consider using `i128` instead
55+
= help: consider using the type `i128` instead
5656

57-
warning: literal out of range for i8
57+
warning: literal out of range for `i8`
5858
--> $DIR/type-overflow.rs:21:17
5959
|
6060
LL | let fail = -0b1111_1111i8;
61-
| ^^^^^^^^^^^^^ help: consider using `i16` instead: `0b1111_1111i16`
61+
| ^^^^^^^^^^^^^ help: consider using the type `i16` instead: `0b1111_1111i16`
6262
|
6363
= note: the literal `0b1111_1111i8` (decimal `255`) does not fit into the type `i8` and will become `-1i8`
6464

0 commit comments

Comments
 (0)