Skip to content

Commit

Permalink
remove and forbid unsafe code
Browse files Browse the repository at this point in the history
  • Loading branch information
suaviloquence committed Aug 4, 2024
1 parent 0c5c26d commit 1de5bc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/frontend/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ impl<T> Default for Arena<T> {
}
}

/// Hack to get a constant NonZeroUsize(1). Uses out-of-bounds
/// array access to simulate panicking in a const declaration.
const ONE: NonZeroUsize = match NonZeroUsize::new(1) {
Some(x) => x,
None => [][0],

Check failure on line 35 in src/frontend/arena.rs

View workflow job for this annotation

GitHub Actions / verify formatting and lints

index is out of bounds
};

impl<T> Arena<T> {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self(ArenaInner {
inner: Vec::new(),
// safety: 1 is nonzero
next_ref: unsafe { NonZeroUsize::new_unchecked(1) },
next_ref: ONE,
})
}

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(never_type)]
#![forbid(unsafe_code)]
use std::{env, sync::Arc};

use anyhow::Context;
Expand Down

0 comments on commit 1de5bc6

Please sign in to comment.