Skip to content

Commit d9dc167

Browse files
committed
cast_possible_truncation: issue proper help message
1 parent 0f75581 commit d9dc167

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

clippy_lints/src/casts/cast_possible_truncation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn check(
168168
let suggestion = format!("{cast_to_snip}::try_from({name_of_cast_from})");
169169

170170
span_lint_and_then(cx, CAST_POSSIBLE_TRUNCATION, expr.span, &msg, |diag| {
171-
diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...");
171+
diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...");
172172
diag.span_suggestion_with_style(
173173
expr.span,
174174
"... or use `try_from` and handle the error accordingly",

tests/ui/cast.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ error: casting `f32` to `i32` may truncate the value
4242
LL | 1f32 as i32;
4343
| ^^^^^^^^^^^
4444
|
45-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
45+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
4646
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
4747
help: ... or use `try_from` and handle the error accordingly
4848
|
@@ -55,7 +55,7 @@ error: casting `f32` to `u32` may truncate the value
5555
LL | 1f32 as u32;
5656
| ^^^^^^^^^^^
5757
|
58-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
58+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
5959
help: ... or use `try_from` and handle the error accordingly
6060
|
6161
LL | u32::try_from(1f32);
@@ -75,7 +75,7 @@ error: casting `f64` to `f32` may truncate the value
7575
LL | 1f64 as f32;
7676
| ^^^^^^^^^^^
7777
|
78-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
78+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
7979
help: ... or use `try_from` and handle the error accordingly
8080
|
8181
LL | f32::try_from(1f64);
@@ -87,7 +87,7 @@ error: casting `i32` to `i8` may truncate the value
8787
LL | 1i32 as i8;
8888
| ^^^^^^^^^^
8989
|
90-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
90+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
9191
help: ... or use `try_from` and handle the error accordingly
9292
|
9393
LL | i8::try_from(1i32);
@@ -99,7 +99,7 @@ error: casting `i32` to `u8` may truncate the value
9999
LL | 1i32 as u8;
100100
| ^^^^^^^^^^
101101
|
102-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
102+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
103103
help: ... or use `try_from` and handle the error accordingly
104104
|
105105
LL | u8::try_from(1i32);
@@ -111,7 +111,7 @@ error: casting `f64` to `isize` may truncate the value
111111
LL | 1f64 as isize;
112112
| ^^^^^^^^^^^^^
113113
|
114-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
114+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
115115
help: ... or use `try_from` and handle the error accordingly
116116
|
117117
LL | isize::try_from(1f64);
@@ -123,7 +123,7 @@ error: casting `f64` to `usize` may truncate the value
123123
LL | 1f64 as usize;
124124
| ^^^^^^^^^^^^^
125125
|
126-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
126+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
127127
help: ... or use `try_from` and handle the error accordingly
128128
|
129129
LL | usize::try_from(1f64);
@@ -141,7 +141,7 @@ error: casting `u32` to `u16` may truncate the value
141141
LL | 1f32 as u32 as u16;
142142
| ^^^^^^^^^^^^^^^^^^
143143
|
144-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
144+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
145145
help: ... or use `try_from` and handle the error accordingly
146146
|
147147
LL | u16::try_from(1f32 as u32);
@@ -153,7 +153,7 @@ error: casting `f32` to `u32` may truncate the value
153153
LL | 1f32 as u32 as u16;
154154
| ^^^^^^^^^^^
155155
|
156-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
156+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
157157
help: ... or use `try_from` and handle the error accordingly
158158
|
159159
LL | u32::try_from(1f32) as u16;
@@ -215,7 +215,7 @@ error: casting `i64` to `i8` may truncate the value
215215
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
216216
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
217217
|
218-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
218+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
219219
help: ... or use `try_from` and handle the error accordingly
220220
|
221221
LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed
@@ -227,7 +227,7 @@ error: casting `u64` to `u8` may truncate the value
227227
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
228228
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229229
|
230-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
230+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
231231
help: ... or use `try_from` and handle the error accordingly
232232
|
233233
LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
@@ -239,7 +239,7 @@ error: casting `main::E2` to `u8` may truncate the value
239239
LL | let _ = self as u8;
240240
| ^^^^^^^^^^
241241
|
242-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
242+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
243243
help: ... or use `try_from` and handle the error accordingly
244244
|
245245
LL | let _ = u8::try_from(self);
@@ -259,7 +259,7 @@ error: casting `main::E5` to `i8` may truncate the value
259259
LL | let _ = self as i8;
260260
| ^^^^^^^^^^
261261
|
262-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
262+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
263263
help: ... or use `try_from` and handle the error accordingly
264264
|
265265
LL | let _ = i8::try_from(self);
@@ -277,7 +277,7 @@ error: casting `main::E6` to `i16` may truncate the value
277277
LL | let _ = self as i16;
278278
| ^^^^^^^^^^^
279279
|
280-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
280+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
281281
help: ... or use `try_from` and handle the error accordingly
282282
|
283283
LL | let _ = i16::try_from(self);
@@ -289,7 +289,7 @@ error: casting `main::E7` to `usize` may truncate the value on targets with 32-b
289289
LL | let _ = self as usize;
290290
| ^^^^^^^^^^^^^
291291
|
292-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
292+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
293293
help: ... or use `try_from` and handle the error accordingly
294294
|
295295
LL | let _ = usize::try_from(self);
@@ -301,7 +301,7 @@ error: casting `main::E10` to `u16` may truncate the value
301301
LL | let _ = self as u16;
302302
| ^^^^^^^^^^^
303303
|
304-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
304+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
305305
help: ... or use `try_from` and handle the error accordingly
306306
|
307307
LL | let _ = u16::try_from(self);
@@ -313,7 +313,7 @@ error: casting `u32` to `u8` may truncate the value
313313
LL | let c = (q >> 16) as u8;
314314
| ^^^^^^^^^^^^^^^
315315
|
316-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
316+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
317317
help: ... or use `try_from` and handle the error accordingly
318318
|
319319
LL | let c = u8::try_from((q >> 16));
@@ -325,7 +325,7 @@ error: casting `u32` to `u8` may truncate the value
325325
LL | let c = (q / 1000) as u8;
326326
| ^^^^^^^^^^^^^^^^
327327
|
328-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
328+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
329329
help: ... or use `try_from` and handle the error accordingly
330330
|
331331
LL | let c = u8::try_from((q / 1000));

tests/ui/cast_size.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: casting `isize` to `i8` may truncate the value
44
LL | 1isize as i8;
55
| ^^^^^^^^^^^^
66
|
7-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
7+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
88
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
99
help: ... or use `try_from` and handle the error accordingly
1010
|
@@ -43,7 +43,7 @@ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wi
4343
LL | 1isize as i32;
4444
| ^^^^^^^^^^^^^
4545
|
46-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
46+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
4747
help: ... or use `try_from` and handle the error accordingly
4848
|
4949
LL | i32::try_from(1isize);
@@ -55,7 +55,7 @@ error: casting `isize` to `u32` may truncate the value on targets with 64-bit wi
5555
LL | 1isize as u32;
5656
| ^^^^^^^^^^^^^
5757
|
58-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
58+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
5959
help: ... or use `try_from` and handle the error accordingly
6060
|
6161
LL | u32::try_from(1isize);
@@ -67,7 +67,7 @@ error: casting `usize` to `u32` may truncate the value on targets with 64-bit wi
6767
LL | 1usize as u32;
6868
| ^^^^^^^^^^^^^
6969
|
70-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
70+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
7171
help: ... or use `try_from` and handle the error accordingly
7272
|
7373
LL | u32::try_from(1usize);
@@ -79,7 +79,7 @@ error: casting `usize` to `i32` may truncate the value on targets with 64-bit wi
7979
LL | 1usize as i32;
8080
| ^^^^^^^^^^^^^
8181
|
82-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
82+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
8383
help: ... or use `try_from` and handle the error accordingly
8484
|
8585
LL | i32::try_from(1usize);
@@ -99,7 +99,7 @@ error: casting `i64` to `isize` may truncate the value on targets with 32-bit wi
9999
LL | 1i64 as isize;
100100
| ^^^^^^^^^^^^^
101101
|
102-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
102+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
103103
help: ... or use `try_from` and handle the error accordingly
104104
|
105105
LL | isize::try_from(1i64);
@@ -111,7 +111,7 @@ error: casting `i64` to `usize` may truncate the value on targets with 32-bit wi
111111
LL | 1i64 as usize;
112112
| ^^^^^^^^^^^^^
113113
|
114-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
114+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
115115
help: ... or use `try_from` and handle the error accordingly
116116
|
117117
LL | usize::try_from(1i64);
@@ -123,7 +123,7 @@ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wi
123123
LL | 1u64 as isize;
124124
| ^^^^^^^^^^^^^
125125
|
126-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
126+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
127127
help: ... or use `try_from` and handle the error accordingly
128128
|
129129
LL | isize::try_from(1u64);
@@ -141,7 +141,7 @@ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wi
141141
LL | 1u64 as usize;
142142
| ^^^^^^^^^^^^^
143143
|
144-
= help: if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...
144+
= help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
145145
help: ... or use `try_from` and handle the error accordingly
146146
|
147147
LL | usize::try_from(1u64);

0 commit comments

Comments
 (0)