Skip to content

Commit 236f823

Browse files
sub_ptr() is equivalent to usize::try_from().unwrap_unchecked(), not usize::from().unwrap_unchecked().
`usize::from()` gives a `usize`, not `Result<usize>`, and `usize: From<isize>` is not implemented.
1 parent 6b3cd03 commit 236f823

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<T: ?Sized> *const T {
731731
/// This computes the same value that [`offset_from`](#method.offset_from)
732732
/// would compute, but with the added precondition that the offset is
733733
/// guaranteed to be non-negative. This method is equivalent to
734-
/// `usize::from(self.offset_from(origin)).unwrap_unchecked()`,
734+
/// `usize::try_from(self.offset_from(origin)).unwrap_unchecked()`,
735735
/// but it provides slightly more information to the optimizer, which can
736736
/// sometimes allow it to optimize slightly better with some backends.
737737
///

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl<T: ?Sized> *mut T {
904904
/// This computes the same value that [`offset_from`](#method.offset_from)
905905
/// would compute, but with the added precondition that the offset is
906906
/// guaranteed to be non-negative. This method is equivalent to
907-
/// `usize::from(self.offset_from(origin)).unwrap_unchecked()`,
907+
/// `usize::try_from(self.offset_from(origin)).unwrap_unchecked()`,
908908
/// but it provides slightly more information to the optimizer, which can
909909
/// sometimes allow it to optimize slightly better with some backends.
910910
///

0 commit comments

Comments
 (0)