From e93776960eaa3da167ba581b95ee3c26d1ed1186 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Wed, 8 May 2024 06:30:08 -0700 Subject: [PATCH] Update Panic documentation and #[track_caller] (#1447) This is stuff I missed in #1442 Signed-off-by: Joe Richey Co-authored-by: Diggory Hardy --- CHANGELOG.md | 2 +- rand_core/src/le.rs | 10 ++++++++++ rand_core/src/lib.rs | 1 - rand_distr/src/weighted_tree.rs | 1 + src/seq/index.rs | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4499433951..583f162a78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update. - Bump the MSRV to 1.61.0 - Rename `Rng::gen` to `Rng::random` to avoid conflict with the new `gen` keyword in Rust 2024 (#1435) - Move all benchmarks to new `benches` crate (#1439) -- Annotate panicking methods with `#[track_caller]` (#1442) +- Annotate panicking methods with `#[track_caller]` (#1442, #1447) ## [0.9.0-alpha.1] - 2024-03-18 - Add the `Slice::num_choices` method to the Slice distribution (#1402) diff --git a/rand_core/src/le.rs b/rand_core/src/le.rs index 89e5e729c8..92ba7d755c 100644 --- a/rand_core/src/le.rs +++ b/rand_core/src/le.rs @@ -12,7 +12,12 @@ //! useful functions available. /// Reads unsigned 32 bit integers from `src` into `dst`. +/// +/// # Panics +/// +/// If `dst` has insufficent space (`4*dst.len() < src.len()`). #[inline] +#[track_caller] pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { assert!(src.len() >= 4 * dst.len()); for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(4)) { @@ -21,7 +26,12 @@ pub fn read_u32_into(src: &[u8], dst: &mut [u32]) { } /// Reads unsigned 64 bit integers from `src` into `dst`. +/// +/// # Panics +/// +/// If `dst` has insufficent space (`8*dst.len() < src.len()`). #[inline] +#[track_caller] pub fn read_u64_into(src: &[u8], dst: &mut [u64]) { assert!(src.len() >= 8 * dst.len()); for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) { diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 07e2b4b5c0..d0c8af065c 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -438,7 +438,6 @@ pub trait SeedableRng: Sized { /// [`try_from_os_rng`]: SeedableRng::try_from_os_rng #[cfg(feature = "getrandom")] #[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] - #[track_caller] fn from_os_rng() -> Self { match Self::try_from_os_rng() { Ok(res) => res, diff --git a/rand_distr/src/weighted_tree.rs b/rand_distr/src/weighted_tree.rs index e8a3681f3c..c292578bf4 100644 --- a/rand_distr/src/weighted_tree.rs +++ b/rand_distr/src/weighted_tree.rs @@ -290,6 +290,7 @@ impl + Weight> impl + Weight> Distribution for WeightedTreeIndex { + #[track_caller] fn sample(&self, rng: &mut R) -> usize { self.try_sample(rng).unwrap() } diff --git a/src/seq/index.rs b/src/seq/index.rs index e7b1e2b22f..e34b1c2ca6 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -219,6 +219,7 @@ impl ExactSizeIterator for IndexVecIntoIter {} /// to adapt the internal `sample_floyd` implementation. /// /// Panics if `amount > length`. +#[track_caller] pub fn sample(rng: &mut R, length: usize, amount: usize) -> IndexVec where R: Rng + ?Sized { if amount > length {