From 951def6e35abbdc575a67afff638dc086ccee999 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sun, 13 Oct 2024 09:36:40 +0000 Subject: [PATCH] refactor(codegen): clarify safety comments in `CodeBuffer` (#6494) --- crates/oxc_codegen/src/code_buffer.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/oxc_codegen/src/code_buffer.rs b/crates/oxc_codegen/src/code_buffer.rs index 339a8ee11..cf071acf1 100644 --- a/crates/oxc_codegen/src/code_buffer.rs +++ b/crates/oxc_codegen/src/code_buffer.rs @@ -339,9 +339,7 @@ impl CodeBuffer { } #[cfg(not(debug_assertions))] { - // SAFETY: `buf` is valid UTF-8 because of invariants upheld by - // CodeBuffer. If, for some reason, it is not, this is caused by - // improper use of `unsafe` printing methods. + // SAFETY: All methods of `CodeBuffer` ensure `buf` is valid UTF-8 unsafe { String::from_utf8_unchecked(take(&mut self.buf)) } } } @@ -359,7 +357,7 @@ impl From for String { if cfg!(debug_assertions) { String::from_utf8(buffer.buf).unwrap() } else { - // SAFETY: `buf` is valid UTF-8 because of invariants upheld by `CodeBuffer` + // SAFETY: All methods of `CodeBuffer` ensure `buf` is valid UTF-8 unsafe { String::from_utf8_unchecked(buffer.buf) } } }