Skip to content

Commit 466646f

Browse files
test: add test case to cast_possible_wrap
1 parent 2d4c45f commit 466646f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tests/ui/cast.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,13 @@ mod issue14150 {
582582
//~^ cast_possible_wrap
583583
}
584584
}
585+
586+
fn issue16045() {
587+
fn f() -> Result<(), ()> {
588+
let val = Ok::<_, ()>(0u8);
589+
_ = val? as i8;
590+
//~^ cast_possible_wrap
591+
592+
Ok(())
593+
}
594+
}

tests/ui/cast.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,5 +764,11 @@ error: casting `u8` to `i8` may wrap around the value
764764
LL | _ = 1u8 as i8;
765765
| ^^^^^^^^^
766766

767-
error: aborting due to 94 previous errors
767+
error: casting `u8` to `i8` may wrap around the value
768+
--> tests/ui/cast.rs:589:13
769+
|
770+
LL | _ = val? as i8;
771+
| ^^^^^^^^^^ help: if this is intentional, use `cast_signed()` instead: `val?.cast_signed()`
772+
773+
error: aborting due to 95 previous errors
768774

0 commit comments

Comments
 (0)