Closed
Description
The function is new, cc #135243
But there's a bunch of places in the code that can be simplified now that it exists. A couple I found quickly:
library/alloc\src\rc.rs
3032: NonNull::new_unchecked(ptr::without_provenance_mut::<RcInner<T>>(usize::MAX))
3059: NonNull::new_unchecked(ptr::without_provenance_mut::<RcInner<T>>(usize::MAX))
library/alloc\src\sync.rs
2692: NonNull::new_unchecked(ptr::without_provenance_mut::<ArcInner<T>>(usize::MAX))
2722: NonNull::new_unchecked(ptr::without_provenance_mut::<ArcInner<T>>(usize::MAX))
library/core\src\alloc\layout.rs
237: unsafe { NonNull::new_unchecked(crate::ptr::without_provenance_mut::<u8>(self.align())) }
library/std\src\io\error\repr_bitpacked.rs
179: unsafe { NonNull::new_unchecked(ptr::without_provenance_mut(utagged)) },
196: unsafe { NonNull::new_unchecked(ptr::without_provenance_mut(utagged)) },
It would be nice to simplify those like
- NonNull::new_unchecked(ptr::without_provenance_mut::<RcInner<T>>(usize::MAX))
+ NonNull::without_provenance::<RcInner<T>>(NonZeroUsize::MAX)
and
- unsafe { NonNull::new_unchecked(crate::ptr::without_provenance_mut::<u8>(self.align())) }
+ NonNull::without_provenance::<u8>(self.alignment.as_nonzero())
(or whatever it would be) to have shorter code that needs to prove fewer soundness preconditions.
Metadata
Metadata
Assignees
Labels
Area: Strict provenance for raw pointersCategory: PRs that clean code up or issues documenting cleanup.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: An issue involves lots of work and is better handled as many small tasks.Relevant to the library team, which will review and decide on the PR/issue.