]> git.lizzy.rs Git - rust.git/commitdiff
move ZST assertion up, for better errors
authorRalf Jung <post@ralfj.de>
Fri, 28 Feb 2020 13:08:48 +0000 (14:08 +0100)
committerRalf Jung <post@ralfj.de>
Fri, 28 Feb 2020 15:07:12 +0000 (16:07 +0100)
src/librustc/mir/interpret/value.rs

index c931fcf71e39d3dcc43903cebfbc2eb3351534dc..2be60d35af33060b23fea035f38f277dbea292df 100644 (file)
@@ -368,10 +368,10 @@ pub fn to_bits_or_ptr(
         target_size: Size,
         cx: &impl HasDataLayout,
     ) -> Result<u128, Pointer<Tag>> {
+        assert_ne!(target_size.bytes(), 0, "you should never look at the bits of a ZST");
         match self {
             Scalar::Raw { data, size } => {
                 assert_eq!(target_size.bytes(), size as u64);
-                assert_ne!(size, 0, "you should never look at the bits of a ZST");
                 Scalar::check_data(data, size);
                 Ok(data)
             }
@@ -386,10 +386,10 @@ pub fn to_bits_or_ptr(
     /// It is just a helper for other methods in this file.
     #[inline]
     fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
+        assert_ne!(target_size.bytes(), 0, "you should never look at the bits of a ZST");
         match self {
             Scalar::Raw { data, size } => {
                 assert_eq!(target_size.bytes(), size as u64);
-                assert_ne!(size, 0, "you should never look at the bits of a ZST");
                 Scalar::check_data(data, size);
                 Ok(data)
             }