Skip to content

Commit

Permalink
Update Panic documentation and #[track_caller]
Browse files Browse the repository at this point in the history
This is stuff I missed in #1442

Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed May 8, 2024
1 parent 1f81878 commit ac8e309
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions rand_core/src/le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions rand_distr/src/weighted_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl<W: Clone + PartialEq + PartialOrd + SampleUniform + SubAssign<W> + Weight>
impl<W: Clone + PartialEq + PartialOrd + SampleUniform + SubAssign<W> + Weight> Distribution<usize>
for WeightedTreeIndex<W>
{
#[track_caller]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
self.try_sample(rng).unwrap()
}
Expand Down
1 change: 1 addition & 0 deletions src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl ExactSizeIterator for IndexVecIntoIter {}
/// to adapt the internal `sample_floyd` implementation.
///
/// Panics if `amount > length`.
#[track_caller]
pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
where R: Rng + ?Sized {
if amount > length {
Expand Down

0 comments on commit ac8e309

Please sign in to comment.