]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/interpret/validity.rs
fix rustfmt fallout
[rust.git] / src / librustc_mir / interpret / validity.rs
index 12e8cb6071d92b31453da434edddfc1b29bf5d65..d0fef08bb60c743034e73da2dcc9f8b83be79a8b 100644 (file)
@@ -115,11 +115,11 @@ fn write_path(out: &mut String, path: &Vec<PathElem>) {
             TupleElem(idx) => write!(out, ".{}", idx),
             ArrayElem(idx) => write!(out, "[{}]", idx),
             Deref =>
-            // This does not match Rust syntax, but it is more readable for long paths -- and
-            // some of the other items here also are not Rust syntax.  Actually we can't
-            // even use the usual syntax because we are just showing the projections,
-            // not the root.
             {
+                // This does not match Rust syntax, but it is more readable for long paths -- and
+                // some of the other items here also are not Rust syntax.  Actually we can't
+                // even use the usual syntax because we are just showing the projections,
+                // not the root.
                 write!(out, ".<deref>")
             }
             Tag => write!(out, ".<enum-tag>"),
@@ -207,8 +207,8 @@ fn aggregate_field_path_elem(&mut self, layout: TyLayout<'tcx>, field: usize) ->
                 // we might be projecting *to* a variant, or to a field *in*a variant.
                 match layout.variants {
                     layout::Variants::Single { index } =>
-                    // Inside a variant
                     {
+                        // Inside a variant
                         PathElem::Field(def.variants[index].fields[field].ident.name)
                     }
                     _ => bug!(),
@@ -608,9 +608,14 @@ fn visit_aggregate(
                     return Ok(());
                 }
                 // This is the element type size.
-                let ty_size = self.ecx.layout_of(tys)?.size;
+                let layout = self.ecx.layout_of(tys)?;
+                // Empty tuples and fieldless structs (the only ZSTs that allow reaching this code)
+                // have no data to be checked.
+                if layout.is_zst() {
+                    return Ok(());
+                }
                 // This is the size in bytes of the whole array.
-                let size = ty_size * len;
+                let size = layout.size * len;
                 // Size is not 0, get a pointer.
                 let ptr = self.ecx.force_ptr(mplace.ptr)?;
 
@@ -640,7 +645,7 @@ fn visit_aggregate(
                                 // Some byte was undefined, determine which
                                 // element that byte belongs to so we can
                                 // provide an index.
-                                let i = (offset.bytes() / ty_size.bytes()) as usize;
+                                let i = (offset.bytes() / layout.size.bytes()) as usize;
                                 self.path.push(PathElem::ArrayElem(i));
 
                                 throw_validation_failure!("undefined bytes", self.path)