Skip to content

Commit

Permalink
refactor(codegen): clarify safety comments in CodeBuffer (#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 13, 2024
1 parent 84a51ee commit 951def6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions crates/oxc_codegen/src/code_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
}
}
Expand All @@ -359,7 +357,7 @@ impl From<CodeBuffer> 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) }
}
}
Expand Down

0 comments on commit 951def6

Please sign in to comment.