Skip to content

Commit

Permalink
Remove unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski authored and orium committed Nov 29, 2024
1 parent 17d78bb commit e2036a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! [Cloudflare Workers]: https://www.cloudflare.com/en-gb/products/cloudflare-workers/
//! [`HtmlRewriter`]: struct.HtmlRewriter.html
//! [`rewrite_str`]: fn.rewrite_str.html
#![forbid(unsafe_code)]
#![allow(clippy::default_trait_access)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::redundant_pub_crate)]
Expand Down
3 changes: 0 additions & 3 deletions src/rewritable_units/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ pub trait StreamingHandler: Send {
// Safety: due to lack of Sync, this trait must not have `&self` methods
}

/// Avoid requring `StreamingHandler` to be `Sync`.
/// It only has a method taking exclusive ownership, so there's no sharing possible.
unsafe impl Sync for StringChunk {}
impl RefUnwindSafe for StringChunk {}
impl UnwindSafe for StringChunk {}

Expand Down
5 changes: 2 additions & 3 deletions src/rewritable_units/text_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,8 @@ impl IncompleteUtf8Resync {
.ok_or(Utf8Error)?
.copy_from_slice(invalid);
self.char_len = invalid.len() as _;
// valid_up_to promises it is valid
debug_assert!(std::str::from_utf8(valid).is_ok());
let valid = unsafe { std::str::from_utf8_unchecked(valid) };
// valid_up_to promises it is always valid
let valid = std::str::from_utf8(valid).map_err(|_| Utf8Error)?;
Ok((valid, b""))
}
}
Expand Down

0 comments on commit e2036a8

Please sign in to comment.