Skip to content

Commit 7dd7174

Browse files
committed
make the note more terse
1 parent 24b1b71 commit 7dd7174

1 file changed

Lines changed: 1 addition & 12 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,24 +497,13 @@ pub fn try_cast_mut<
497497
/// ## Failure
498498
///
499499
/// * If the target type has a greater alignment requirement and the input slice
500-
/// isn't aligned.
500+
/// isn't aligned. **Note:** This rule applies even if the slice is empty!
501501
/// * If the target element type is a different size from the current element
502502
/// type, and the output slice wouldn't be a whole number of elements when
503503
/// accounting for the size change (eg: 3 `u16` values is 1.5 `u32` values, so
504504
/// that's a failure).
505505
/// * Similarly, you can't convert between a [ZST](https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts)
506506
/// and a non-ZST.
507-
///
508-
/// ## Note
509-
///
510-
/// An empty input slice is **not** exempt from the alignment requirement. If
511-
/// the target type has a greater alignment than the source type then this can
512-
/// still fail (and [`cast_slice`] can still panic) even when the slice is
513-
/// empty, because the slice's data pointer must satisfy the target alignment.
514-
/// An empty slice such as `&[]` typically carries a dangling pointer aligned
515-
/// only to the source type, which may be under-aligned for the target. If you
516-
/// need casting an empty slice to always succeed, test for emptiness yourself
517-
/// and substitute an empty slice of the target type.
518507
#[inline]
519508
pub fn try_cast_slice<A: NoUninit, B: AnyBitPattern>(
520509
a: &[A],

0 commit comments

Comments
 (0)