]> git.lizzy.rs Git - rust.git/commitdiff
Simplify the char correctness check
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Mon, 30 Jul 2018 13:42:11 +0000 (15:42 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Wed, 1 Aug 2018 13:29:35 +0000 (15:29 +0200)
src/librustc_mir/interpret/eval_context.rs

index ada304b6997137d842fd15fb837e0bfe13fd3951..6a1eb762e9529a7ba8fe849627c3c09dff645fb6 100644 (file)
@@ -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));
                 }
             }
             _ => {},