Skip to content

Commit 32eb10f

Browse files
committed
Simplify the char correctness check
1 parent d0b315f commit 32eb10f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
13651365
// has no special checks for chars
13661366
match ty.sty {
13671367
ty::TyChar => {
1368-
assert_eq!(size.bytes(), 4);
1369-
let c = self.memory.read_scalar(ptr, ptr_align, Size::from_bytes(4))?.read()?.to_bits(Size::from_bytes(4))? as u32;
1370-
match ::std::char::from_u32(c) {
1371-
Some(..) => (),
1372-
None => return err!(InvalidChar(c as u128)),
1368+
debug_assert_eq!(size.bytes(), 4);
1369+
if ::std::char::from_u32(bits as u32).is_none() {
1370+
return err!(InvalidChar(bits));
13731371
}
13741372
}
13751373
_ => {},

0 commit comments

Comments
 (0)