Skip to content

Commit af63746

Browse files
committed
Auto merge of rust-lang#116188 - saethlin:maybe-regression, r=<try>
Clamp instead of asserting in FileEncoder::write_with r? `@WaffleLapkin` If this isn't the regression mentioned in rust-lang#115542 (comment) I'd have to actually look into it.
2 parents 5ae769f + 4a17971 commit af63746

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

compiler/rustc_serialize/src/opaque.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,8 @@ impl FileEncoder {
131131
let buf = unsafe { self.buffer_empty().first_chunk_mut::<N>().unwrap_unchecked() };
132132
let written = visitor(buf);
133133
// We have to ensure that an errant visitor cannot cause self.buffered to exeed BUF_SIZE.
134-
if written > N {
135-
Self::panic_invalid_write::<N>(written);
136-
}
137-
self.buffered += written;
138-
}
139-
140-
#[cold]
141-
#[inline(never)]
142-
fn panic_invalid_write<const N: usize>(written: usize) {
143-
panic!("FileEncoder::write_with::<{N}> cannot be used to write {written} bytes");
134+
debug_assert!(written <= N);
135+
self.buffered += written.min(N);
144136
}
145137

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

0 commit comments

Comments
 (0)