Skip to content

Commit 0eb16ea

Browse files
Add test to ensure that suggestions are only emitted if MSRV supports it
1 parent 064825e commit 0eb16ea

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/ui/cast.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,16 @@ fn issue12721() {
569569
(255 % 999999u64) as u8;
570570
//~^ cast_possible_truncation
571571
}
572+
573+
mod issue14150 {
574+
#[clippy::msrv = "1.87"]
575+
fn msrv_supports_cast_signed() {
576+
_ = 1u8 as i8;
577+
//~^ cast_possible_wrap
578+
}
579+
#[clippy::msrv = "1.86"]
580+
fn msrv_doesnt_supports_cast_signed() {
581+
_ = 1u8 as i8;
582+
//~^ cast_possible_wrap
583+
}
584+
}

tests/ui/cast.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,5 +752,17 @@ LL - (255 % 999999u64) as u8;
752752
LL + u8::try_from(255 % 999999u64);
753753
|
754754

755-
error: aborting due to 92 previous errors
755+
error: casting `u8` to `i8` may wrap around the value
756+
--> tests/ui/cast.rs:576:13
757+
|
758+
LL | _ = 1u8 as i8;
759+
| ^^^^^^^^^ help: if this is intentional, consider using `cast_signed()` instead: `1u8.cast_signed()`
760+
761+
error: casting `u8` to `i8` may wrap around the value
762+
--> tests/ui/cast.rs:581:13
763+
|
764+
LL | _ = 1u8 as i8;
765+
| ^^^^^^^^^
766+
767+
error: aborting due to 94 previous errors
756768

0 commit comments

Comments
 (0)