From d376ac819cdc1212502315f98d45e559cbaa3731 Mon Sep 17 00:00:00 2001 From: "Chai T. Rex" Date: Mon, 19 Aug 2024 19:12:05 -0400 Subject: [PATCH] `core::` -> `crate::` and `# Safety` docs for macros --- library/core/src/num/int_sqrt.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/library/core/src/num/int_sqrt.rs b/library/core/src/num/int_sqrt.rs index 7d02d456a4c02..5755294623f40 100644 --- a/library/core/src/num/int_sqrt.rs +++ b/library/core/src/num/int_sqrt.rs @@ -159,6 +159,10 @@ macro_rules! unsigned_fn { } /// Generates the first stage of the computation after normalization. +/// +/// # Safety +/// +/// `$n` must be nonzero. macro_rules! first_stage { ($original_bits:literal, $n:ident) => {{ const N_SHIFT: u32 = $original_bits - 8; @@ -169,6 +173,10 @@ macro_rules! first_stage { } /// Generates a middle stage of the computation. +/// +/// # Safety +/// +/// `$s` must be nonzero. macro_rules! middle_stage { ($original_bits:literal, $ty:ty, $n:ident, $s:ident, $r:ident) => {{ // Inform the optimizer that `$s` is nonzero. This will allow it to @@ -219,6 +227,10 @@ macro_rules! middle_stage { } /// Generates the last stage of the computation before denormalization. +/// +/// # Safety +/// +/// `$s` must be nonzero. macro_rules! last_stage { ($ty:ty, $n:ident, $s:ident, $r:ident) => {{ // Inform the optimizer that `$s` is nonzero. This will allow it to @@ -226,7 +238,7 @@ macro_rules! last_stage { // division below. // // SAFETY: See the proof in the `middle_stage` macro above. - unsafe { core::hint::assert_unchecked($s != 0) }; + unsafe { crate::hint::assert_unchecked($s != 0) }; const HALF_BITS: u32 = <$ty>::BITS >> 1; const QUARTER_BITS: u32 = <$ty>::BITS >> 2; @@ -248,6 +260,10 @@ macro_rules! last_stage { /// Generates the stages of the computation between normalization and /// denormalization for [`u16`](prim@u16). +/// +/// # Safety +/// +/// `$n` must be nonzero. macro_rules! u16_stages { ($n:ident) => {{ let (s, r) = first_stage!(16, $n); @@ -257,6 +273,10 @@ macro_rules! u16_stages { /// Generates the stages of the computation between normalization and /// denormalization for [`u32`](prim@u32). +/// +/// # Safety +/// +/// `$n` must be nonzero. macro_rules! u32_stages { ($n:ident) => {{ let (s, r) = first_stage!(32, $n); @@ -267,6 +287,10 @@ macro_rules! u32_stages { /// Generates the stages of the computation between normalization and /// denormalization for [`u64`](prim@u64). +/// +/// # Safety +/// +/// `$n` must be nonzero. macro_rules! u64_stages { ($n:ident) => {{ let (s, r) = first_stage!(64, $n); @@ -278,6 +302,10 @@ macro_rules! u64_stages { /// Generates the stages of the computation between normalization and /// denormalization for [`u128`](prim@u128). +/// +/// # Safety +/// +/// `$n` must be nonzero. macro_rules! u128_stages { ($n:ident) => {{ let (s, r) = first_stage!(128, $n);