Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,8 @@ impl FileEncoder {
let buf = unsafe { self.buffer_empty().first_chunk_mut::<N>().unwrap_unchecked() };
let written = visitor(buf);
// We have to ensure that an errant visitor cannot cause self.buffered to exeed BUF_SIZE.
if written > N {
Self::panic_invalid_write::<N>(written);
}
self.buffered += written;
}

#[cold]
#[inline(never)]
fn panic_invalid_write<const N: usize>(written: usize) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't caught it during the original review, but if we'll leave this in, this funciton should probably return !

panic!("FileEncoder::write_with::<{N}> cannot be used to write {written} bytes");
debug_assert!(written <= N);
self.buffered += written.min(N);
}

/// Helper for calls where [`FileEncoder::write_with`] always writes the whole array.
Expand Down