Skip to content

Commit

Permalink
Remove unsafe annotations for the options API.
Browse files Browse the repository at this point in the history
These used to have safety considerations although none do anymore, but
they require validation or there could be runtime panics.

- Addresses #100
- Addresses #138
  • Loading branch information
Alexhuszagh committed Sep 15, 2024
1 parent aeab322 commit b6a84b0
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 691 deletions.
8 changes: 5 additions & 3 deletions lexical-parse-float/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<const SIZE: usize> StackVec<SIZE> {
///
/// Safe if `self.len() < self.capacity()`.
#[inline(always)]
pub unsafe fn push_unchecked(&mut self, value: Limb) {
unsafe fn push_unchecked(&mut self, value: Limb) {
debug_assert!(self.len() < self.capacity());
// SAFETY: safe, capacity is less than the current size.
unsafe {
Expand Down Expand Up @@ -419,7 +419,7 @@ impl<const SIZE: usize> StackVec<SIZE> {
///
/// Safe if `self.len() > 0`.
#[inline(always)]
pub unsafe fn pop_unchecked(&mut self) -> Limb {
unsafe fn pop_unchecked(&mut self) -> Limb {
debug_assert!(!self.is_empty());
// SAFETY: safe if `self.length > 0`.
// We have a trivial drop and copy, so this is safe.
Expand All @@ -445,7 +445,7 @@ impl<const SIZE: usize> StackVec<SIZE> {
///
/// Safe if `self.len() + slc.len() <= self.capacity()`.
#[inline(always)]
pub unsafe fn extend_unchecked(&mut self, slc: &[Limb]) {
unsafe fn extend_unchecked(&mut self, slc: &[Limb]) {
let index = self.len();
let new_len = index + slc.len();
debug_assert!(self.len() + slc.len() <= self.capacity());
Expand Down Expand Up @@ -1228,6 +1228,7 @@ pub fn large_mul<const SIZE: usize>(x: &mut StackVec<SIZE>, y: &[Limb]) -> Optio
// multiplication.
if y.len() == 1 {
// SAFETY: safe since `y.len() == 1`.
// NOTE: The compiler does not seem to optimize this out correctly.
small_mul(x, unsafe { index_unchecked!(y[0]) })?;
} else {
*x = long_mul(y, x)?;
Expand Down Expand Up @@ -1369,6 +1370,7 @@ pub fn shl_limbs<const SIZE: usize>(x: &mut StackVec<SIZE>, n: usize) -> Option<
let x_len = x.len();
let ptr = x.as_mut_ptr();
let src = ptr;
// FIXME: Change to `split_at_mut` and `clone_from_slice`?
// SAFE: since x is not empty, and `x.len() + n <= x.capacity()`.
unsafe {
// Move the elements.
Expand Down
Loading

0 comments on commit b6a84b0

Please sign in to comment.