From ac8e3097b81c085fdd79386f266f8eb04e01df75 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 7 May 2024 04:13:42 -0700 Subject: [PATCH] Update Panic documentation and #[track_caller] This is stuff I missed in #1442 Signed-off-by: Joe Richey --- 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 6617ea1c80..70424e6c9c 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -385,7 +385,6 @@ pub trait SeedableRng: Sized { /// [`getrandom`]: https://docs.rs/getrandom #[cfg(feature = "getrandom")] #[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] - #[track_caller] fn from_entropy() -> Self { let mut seed = Self::Seed::default(); if let Err(err) = getrandom::getrandom(seed.as_mut()) { 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 {