Skip to content

Commit 959e7bb

Browse files
Apply suggestions from code review
1 parent 739dc86 commit 959e7bb

File tree

4 files changed

+47
-64
lines changed

4 files changed

+47
-64
lines changed

clippy_lints/src/casts/cast_possible_wrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(super) fn check(
108108

109109
diag.span_suggestion(
110110
expr.span,
111-
format!("if this is intentional, consider using `{method}` instead"),
111+
format!("if this is intentional, use `{method}` instead"),
112112
format!("{}.{method}", sugg.maybe_paren()),
113113
app,
114114
);

clippy_lints/src/casts/cast_sign_loss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(super) fn check<'cx>(
6666

6767
diag.span_suggestion(
6868
expr.span,
69-
format!("if this is intentional, consider using `{method}` instead"),
69+
format!("if this is intentional, use `{method}` instead"),
7070
format!("{}.{method}", sugg.maybe_paren()),
7171
app,
7272
);

clippy_lints/src/casts/utils.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,9 @@ pub(super) enum CastTo {
6969
/// only in signedness, otherwise `None`. The value of `Some` is which
7070
/// signedness is casted to.
7171
pub(super) fn is_signedness_cast(cast_from: Ty<'_>, cast_to: Ty<'_>) -> Option<CastTo> {
72-
if !cast_from.is_integral() || !cast_to.is_integral() {
73-
return None;
74-
}
75-
if cast_from.is_signed() == cast_to.is_signed() {
76-
return None;
77-
}
78-
if as_uint_ty(cast_from) != as_uint_ty(cast_to) {
79-
return None;
80-
}
81-
82-
if cast_to.is_signed() {
83-
Some(CastTo::Signed)
84-
} else {
85-
Some(CastTo::Unsigned)
86-
}
87-
}
88-
fn as_uint_ty(ty: Ty<'_>) -> Option<UintTy> {
89-
match ty.kind() {
90-
ty::Uint(uint_ty) => Some(*uint_ty),
91-
ty::Int(int_ty) => Some(int_ty.to_unsigned()),
72+
match (cast_from.kind(), cast_to.kind()) {
73+
(ty::Int(from), ty::Uint(to)) if from.to_unsigned() == *to => Some(CastTo::Unsigned),
74+
(ty::Uint(from), ty::Int(to)) if *from == to.to_unsigned() => Some(CastTo::Signed),
9275
_ => None,
9376
}
9477
}

tests/ui/cast.stderr

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ error: casting `u8` to `i8` may wrap around the value
194194
--> tests/ui/cast.rs:88:5
195195
|
196196
LL | 1u8 as i8;
197-
| ^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u8.cast_signed()`
197+
| ^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1u8.cast_signed()`
198198
|
199199
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
200200
= help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]`
@@ -203,25 +203,25 @@ error: casting `u16` to `i16` may wrap around the value
203203
--> tests/ui/cast.rs:91:5
204204
|
205205
LL | 1u16 as i16;
206-
| ^^^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u16.cast_signed()`
206+
| ^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1u16.cast_signed()`
207207

208208
error: casting `u32` to `i32` may wrap around the value
209209
--> tests/ui/cast.rs:94:5
210210
|
211211
LL | 1u32 as i32;
212-
| ^^^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u32.cast_signed()`
212+
| ^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1u32.cast_signed()`
213213

214214
error: casting `u64` to `i64` may wrap around the value
215215
--> tests/ui/cast.rs:97:5
216216
|
217217
LL | 1u64 as i64;
218-
| ^^^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u64.cast_signed()`
218+
| ^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1u64.cast_signed()`
219219

220220
error: casting `usize` to `isize` may wrap around the value
221221
--> tests/ui/cast.rs:100:5
222222
|
223223
LL | 1usize as isize;
224-
| ^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1usize.cast_signed()`
224+
| ^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1usize.cast_signed()`
225225

226226
error: casting `usize` to `i8` may truncate the value
227227
--> tests/ui/cast.rs:104:5
@@ -321,43 +321,43 @@ error: casting `i32` to `u32` may lose the sign of the value
321321
--> tests/ui/cast.rs:138:5
322322
|
323323
LL | -1i32 as u32;
324-
| ^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-1i32).cast_unsigned()`
324+
| ^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-1i32).cast_unsigned()`
325325

326326
error: casting `isize` to `usize` may lose the sign of the value
327327
--> tests/ui/cast.rs:142:5
328328
|
329329
LL | -1isize as usize;
330-
| ^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-1isize).cast_unsigned()`
330+
| ^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-1isize).cast_unsigned()`
331331

332332
error: casting `i8` to `u8` may lose the sign of the value
333333
--> tests/ui/cast.rs:154:5
334334
|
335335
LL | (i8::MIN).abs() as u8;
336-
| ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(i8::MIN).abs().cast_unsigned()`
336+
| ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(i8::MIN).abs().cast_unsigned()`
337337

338338
error: casting `i64` to `u64` may lose the sign of the value
339339
--> tests/ui/cast.rs:159:5
340340
|
341341
LL | (-1i64).abs() as u64;
342-
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-1i64).abs().cast_unsigned()`
342+
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-1i64).abs().cast_unsigned()`
343343

344344
error: casting `isize` to `usize` may lose the sign of the value
345345
--> tests/ui/cast.rs:161:5
346346
|
347347
LL | (-1isize).abs() as usize;
348-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-1isize).abs().cast_unsigned()`
348+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-1isize).abs().cast_unsigned()`
349349

350350
error: casting `i64` to `u64` may lose the sign of the value
351351
--> tests/ui/cast.rs:169:5
352352
|
353353
LL | (unsafe { (-1i64).checked_abs().unwrap_unchecked() }) as u64;
354-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(unsafe { (-1i64).checked_abs().unwrap_unchecked() }).cast_unsigned()`
354+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(unsafe { (-1i64).checked_abs().unwrap_unchecked() }).cast_unsigned()`
355355

356356
error: casting `i64` to `u64` may lose the sign of the value
357357
--> tests/ui/cast.rs:185:5
358358
|
359359
LL | (unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }) as u64;
360-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }).cast_unsigned()`
360+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(unsafe { (-1i64).checked_isqrt().unwrap_unchecked() }).cast_unsigned()`
361361

362362
error: casting `i64` to `i8` may truncate the value
363363
--> tests/ui/cast.rs:237:5
@@ -495,79 +495,79 @@ error: casting `i32` to `u32` may lose the sign of the value
495495
--> tests/ui/cast.rs:438:9
496496
|
497497
LL | (x * x) as u32;
498-
| ^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(x * x).cast_unsigned()`
498+
| ^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(x * x).cast_unsigned()`
499499

500500
error: casting `i32` to `u32` may lose the sign of the value
501501
--> tests/ui/cast.rs:444:32
502502
|
503503
LL | let _a = |x: i32| -> u32 { (x * x * x * x) as u32 };
504-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(x * x * x * x).cast_unsigned()`
504+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(x * x * x * x).cast_unsigned()`
505505

506506
error: casting `i32` to `u32` may lose the sign of the value
507507
--> tests/ui/cast.rs:447:5
508508
|
509509
LL | (2_i32).checked_pow(3).unwrap() as u32;
510-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(2_i32).checked_pow(3).unwrap().cast_unsigned()`
510+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(2_i32).checked_pow(3).unwrap().cast_unsigned()`
511511

512512
error: casting `i32` to `u32` may lose the sign of the value
513513
--> tests/ui/cast.rs:449:5
514514
|
515515
LL | (-2_i32).pow(3) as u32;
516-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-2_i32).pow(3).cast_unsigned()`
516+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-2_i32).pow(3).cast_unsigned()`
517517

518518
error: casting `i32` to `u32` may lose the sign of the value
519519
--> tests/ui/cast.rs:454:5
520520
|
521521
LL | (-5_i32 % 2) as u32;
522-
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-5_i32 % 2).cast_unsigned()`
522+
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-5_i32 % 2).cast_unsigned()`
523523

524524
error: casting `i32` to `u32` may lose the sign of the value
525525
--> tests/ui/cast.rs:457:5
526526
|
527527
LL | (-5_i32 % -2) as u32;
528-
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-5_i32 % -2).cast_unsigned()`
528+
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-5_i32 % -2).cast_unsigned()`
529529

530530
error: casting `i32` to `u32` may lose the sign of the value
531531
--> tests/ui/cast.rs:461:5
532532
|
533533
LL | (-2_i32 >> 1) as u32;
534-
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(-2_i32 >> 1).cast_unsigned()`
534+
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(-2_i32 >> 1).cast_unsigned()`
535535

536536
error: casting `i32` to `u32` may lose the sign of the value
537537
--> tests/ui/cast.rs:465:5
538538
|
539539
LL | (x * x) as u32;
540-
| ^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(x * x).cast_unsigned()`
540+
| ^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(x * x).cast_unsigned()`
541541

542542
error: casting `i32` to `u32` may lose the sign of the value
543543
--> tests/ui/cast.rs:467:5
544544
|
545545
LL | (x * x * x) as u32;
546-
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(x * x * x).cast_unsigned()`
546+
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(x * x * x).cast_unsigned()`
547547

548548
error: casting `i16` to `u16` may lose the sign of the value
549549
--> tests/ui/cast.rs:471:5
550550
|
551551
LL | (y * y * y * y * -2) as u16;
552-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y * y * y * y * -2).cast_unsigned()`
552+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y * y * y * y * -2).cast_unsigned()`
553553

554554
error: casting `i16` to `u16` may lose the sign of the value
555555
--> tests/ui/cast.rs:474:5
556556
|
557557
LL | (y * y * y / y * 2) as u16;
558-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y * y * y / y * 2).cast_unsigned()`
558+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y * y * y / y * 2).cast_unsigned()`
559559

560560
error: casting `i16` to `u16` may lose the sign of the value
561561
--> tests/ui/cast.rs:476:5
562562
|
563563
LL | (y * y / y * 2) as u16;
564-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y * y / y * 2).cast_unsigned()`
564+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y * y / y * 2).cast_unsigned()`
565565

566566
error: casting `i16` to `u16` may lose the sign of the value
567567
--> tests/ui/cast.rs:479:5
568568
|
569569
LL | (y / y * y * -2) as u16;
570-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y / y * y * -2).cast_unsigned()`
570+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y / y * y * -2).cast_unsigned()`
571571

572572
error: equal expressions as operands to `/`
573573
--> tests/ui/cast.rs:479:6
@@ -581,97 +581,97 @@ error: casting `i16` to `u16` may lose the sign of the value
581581
--> tests/ui/cast.rs:483:5
582582
|
583583
LL | (y + y + y + -2) as u16;
584-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y + y + y + -2).cast_unsigned()`
584+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y + y + y + -2).cast_unsigned()`
585585

586586
error: casting `i16` to `u16` may lose the sign of the value
587587
--> tests/ui/cast.rs:486:5
588588
|
589589
LL | (y + y + y + 2) as u16;
590-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(y + y + y + 2).cast_unsigned()`
590+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(y + y + y + 2).cast_unsigned()`
591591

592592
error: casting `i16` to `u16` may lose the sign of the value
593593
--> tests/ui/cast.rs:490:5
594594
|
595595
LL | (z + -2) as u16;
596-
| ^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(z + -2).cast_unsigned()`
596+
| ^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(z + -2).cast_unsigned()`
597597

598598
error: casting `i16` to `u16` may lose the sign of the value
599599
--> tests/ui/cast.rs:493:5
600600
|
601601
LL | (z + z + 2) as u16;
602-
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(z + z + 2).cast_unsigned()`
602+
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(z + z + 2).cast_unsigned()`
603603

604604
error: casting `i32` to `u32` may lose the sign of the value
605605
--> tests/ui/cast.rs:497:9
606606
|
607607
LL | (a * a * b * b * c * c) as u32;
608-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * a * b * b * c * c).cast_unsigned()`
608+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * a * b * b * c * c).cast_unsigned()`
609609

610610
error: casting `i32` to `u32` may lose the sign of the value
611611
--> tests/ui/cast.rs:499:9
612612
|
613613
LL | (a * b * c) as u32;
614-
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * b * c).cast_unsigned()`
614+
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * b * c).cast_unsigned()`
615615

616616
error: casting `i32` to `u32` may lose the sign of the value
617617
--> tests/ui/cast.rs:502:9
618618
|
619619
LL | (a * -b * c) as u32;
620-
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * -b * c).cast_unsigned()`
620+
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * -b * c).cast_unsigned()`
621621

622622
error: casting `i32` to `u32` may lose the sign of the value
623623
--> tests/ui/cast.rs:505:9
624624
|
625625
LL | (a * b * c * c) as u32;
626-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * b * c * c).cast_unsigned()`
626+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * b * c * c).cast_unsigned()`
627627

628628
error: casting `i32` to `u32` may lose the sign of the value
629629
--> tests/ui/cast.rs:507:9
630630
|
631631
LL | (a * -2) as u32;
632-
| ^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * -2).cast_unsigned()`
632+
| ^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * -2).cast_unsigned()`
633633

634634
error: casting `i32` to `u32` may lose the sign of the value
635635
--> tests/ui/cast.rs:510:9
636636
|
637637
LL | (a * b * c * -2) as u32;
638-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a * b * c * -2).cast_unsigned()`
638+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a * b * c * -2).cast_unsigned()`
639639

640640
error: casting `i32` to `u32` may lose the sign of the value
641641
--> tests/ui/cast.rs:513:9
642642
|
643643
LL | (a / b) as u32;
644-
| ^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a / b).cast_unsigned()`
644+
| ^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a / b).cast_unsigned()`
645645

646646
error: casting `i32` to `u32` may lose the sign of the value
647647
--> tests/ui/cast.rs:515:9
648648
|
649649
LL | (a / b * c) as u32;
650-
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a / b * c).cast_unsigned()`
650+
| ^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a / b * c).cast_unsigned()`
651651

652652
error: casting `i32` to `u32` may lose the sign of the value
653653
--> tests/ui/cast.rs:518:9
654654
|
655655
LL | (a / b + b * c) as u32;
656-
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a / b + b * c).cast_unsigned()`
656+
| ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a / b + b * c).cast_unsigned()`
657657

658658
error: casting `i32` to `u32` may lose the sign of the value
659659
--> tests/ui/cast.rs:521:9
660660
|
661661
LL | a.saturating_pow(3) as u32;
662-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `a.saturating_pow(3).cast_unsigned()`
662+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `a.saturating_pow(3).cast_unsigned()`
663663

664664
error: casting `i32` to `u32` may lose the sign of the value
665665
--> tests/ui/cast.rs:524:9
666666
|
667667
LL | (a.abs() * b.pow(2) / c.abs()) as u32
668-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `(a.abs() * b.pow(2) / c.abs()).cast_unsigned()`
668+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `(a.abs() * b.pow(2) / c.abs()).cast_unsigned()`
669669

670670
error: casting `i32` to `u32` may lose the sign of the value
671671
--> tests/ui/cast.rs:532:21
672672
|
673673
LL | let _ = i32::MIN as u32; // cast_sign_loss
674-
| ^^^^^^^^^^^^^^^ help: if this is intentional, consider using `cast_unsigned()` instead: `i32::MIN.cast_unsigned()`
674+
| ^^^^^^^^^^^^^^^ help: if this is intentional, use `cast_unsigned()` instead: `i32::MIN.cast_unsigned()`
675675
...
676676
LL | m!();
677677
| ---- in this macro invocation
@@ -756,7 +756,7 @@ error: casting `u8` to `i8` may wrap around the value
756756
--> tests/ui/cast.rs:576:13
757757
|
758758
LL | _ = 1u8 as i8;
759-
| ^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u8.cast_signed()`
759+
| ^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `1u8.cast_signed()`
760760

761761
error: casting `u8` to `i8` may wrap around the value
762762
--> tests/ui/cast.rs:581:13

0 commit comments

Comments
 (0)