Skip to content

Commit

Permalink
refactor: Be safe (#637)
Browse files Browse the repository at this point in the history
Use a trick suggested by @acl-cqc to remove the `unsafe`.

Drive-by: Remove unneeded clippy annotation.
  • Loading branch information
cqc-alec authored Nov 1, 2023
1 parent d5be87f commit 1a07cd9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/std_extensions/arithmetic/int_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ const fn is_valid_log_width(n: u8) -> bool {
pub const LOG_WIDTH_BOUND: u8 = 7;

/// Type parameter for the log width of the integer.
// SAFETY: unsafe block should be ok as the value is definitely not zero.
#[allow(clippy::assertions_on_constants)]
pub const LOG_WIDTH_TYPE_PARAM: TypeParam = TypeParam::bounded_nat(unsafe {
pub const LOG_WIDTH_TYPE_PARAM: TypeParam = TypeParam::bounded_nat({
assert!(LOG_WIDTH_BOUND > 0);
NonZeroU64::new_unchecked(LOG_WIDTH_BOUND as u64)
NonZeroU64::MIN.saturating_add(LOG_WIDTH_BOUND as u64 - 1)
});

/// Get the log width of the specified type argument or error if the argument
Expand Down
1 change: 0 additions & 1 deletion src/std_extensions/quantum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const fn is_valid_log_denom(n: u8) -> bool {
}

/// Type parameter for the log-denominator of an angle.
#[allow(clippy::assertions_on_constants)]
pub const LOG_DENOM_TYPE_PARAM: TypeParam =
TypeParam::bounded_nat(NonZeroU64::MIN.saturating_add(LOG_DENOM_MAX as u64));

Expand Down

0 comments on commit 1a07cd9

Please sign in to comment.