Skip to content

Commit 7eb64b4

Browse files
committed
flush and assert when counting zero bytes
1 parent c57d778 commit 7eb64b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,14 +733,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
733733
assert_eq!(total_bytes, computed_total_bytes);
734734

735735
if tcx.sess.meta_stats() {
736+
self.opaque.flush().unwrap();
737+
738+
let pos_before_rewind = self.opaque.file().stream_position().unwrap();
736739
let mut zero_bytes = 0;
737-
self.opaque.file().seek(std::io::SeekFrom::Start(0)).unwrap();
740+
self.opaque.file().rewind().unwrap();
738741
let file = std::io::BufReader::new(self.opaque.file());
739742
for e in file.bytes() {
740743
if e.unwrap() == 0 {
741744
zero_bytes += 1;
742745
}
743746
}
747+
assert_eq!(self.opaque.file().stream_position().unwrap(), pos_before_rewind);
744748

745749
let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
746750
let p = |label, bytes| {

0 commit comments

Comments
 (0)