Skip to content

Commit

Permalink
Update Panic documentation and #[track_caller] (#1447)
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>
Co-authored-by: Diggory Hardy <git@dhardy.name>
  • Loading branch information
josephlr and dhardy committed May 8, 2024
1 parent fba5521 commit e937769
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
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
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
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions rand_distr/src/weighted_tree.rs
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
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 e937769

Please sign in to comment.