Skip to content

Commit e937769

Browse files
josephlrdhardy
andauthored
Update Panic documentation and #[track_caller] (#1447)
This is stuff I missed in #1442 Signed-off-by: Joe Richey <[email protected]> Co-authored-by: Diggory Hardy <[email protected]>
1 parent fba5521 commit e937769

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1313
- Bump the MSRV to 1.61.0
1414
- Rename `Rng::gen` to `Rng::random` to avoid conflict with the new `gen` keyword in Rust 2024 (#1435)
1515
- Move all benchmarks to new `benches` crate (#1439)
16-
- Annotate panicking methods with `#[track_caller]` (#1442)
16+
- Annotate panicking methods with `#[track_caller]` (#1442, #1447)
1717

1818
## [0.9.0-alpha.1] - 2024-03-18
1919
- Add the `Slice::num_choices` method to the Slice distribution (#1402)

rand_core/src/le.rs

+10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
//! useful functions available.
1313
1414
/// Reads unsigned 32 bit integers from `src` into `dst`.
15+
///
16+
/// # Panics
17+
///
18+
/// If `dst` has insufficent space (`4*dst.len() < src.len()`).
1519
#[inline]
20+
#[track_caller]
1621
pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
1722
assert!(src.len() >= 4 * dst.len());
1823
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]) {
2126
}
2227

2328
/// Reads unsigned 64 bit integers from `src` into `dst`.
29+
///
30+
/// # Panics
31+
///
32+
/// If `dst` has insufficent space (`8*dst.len() < src.len()`).
2433
#[inline]
34+
#[track_caller]
2535
pub fn read_u64_into(src: &[u8], dst: &mut [u64]) {
2636
assert!(src.len() >= 8 * dst.len());
2737
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) {

rand_core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ pub trait SeedableRng: Sized {
438438
/// [`try_from_os_rng`]: SeedableRng::try_from_os_rng
439439
#[cfg(feature = "getrandom")]
440440
#[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))]
441-
#[track_caller]
442441
fn from_os_rng() -> Self {
443442
match Self::try_from_os_rng() {
444443
Ok(res) => res,

rand_distr/src/weighted_tree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ impl<W: Clone + PartialEq + PartialOrd + SampleUniform + SubAssign<W> + Weight>
290290
impl<W: Clone + PartialEq + PartialOrd + SampleUniform + SubAssign<W> + Weight> Distribution<usize>
291291
for WeightedTreeIndex<W>
292292
{
293+
#[track_caller]
293294
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
294295
self.try_sample(rng).unwrap()
295296
}

src/seq/index.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl ExactSizeIterator for IndexVecIntoIter {}
219219
/// to adapt the internal `sample_floyd` implementation.
220220
///
221221
/// Panics if `amount > length`.
222+
#[track_caller]
222223
pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
223224
where R: Rng + ?Sized {
224225
if amount > length {

0 commit comments

Comments
 (0)