From 32eb10f54d33e7d907975fd1a859d987280c6c48 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 30 Jul 2018 15:42:11 +0200 Subject: [PATCH] Simplify the char correctness check --- src/librustc_mir/interpret/eval_context.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index ada304b6997..6a1eb762e95 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -1365,11 +1365,9 @@ fn validate_scalar( // has no special checks for chars match ty.sty { ty::TyChar => { - assert_eq!(size.bytes(), 4); - let c = self.memory.read_scalar(ptr, ptr_align, Size::from_bytes(4))?.read()?.to_bits(Size::from_bytes(4))? as u32; - match ::std::char::from_u32(c) { - Some(..) => (), - None => return err!(InvalidChar(c as u128)), + debug_assert_eq!(size.bytes(), 4); + if ::std::char::from_u32(bits as u32).is_none() { + return err!(InvalidChar(bits)); } } _ => {}, -- 2.44.0