Extend ptr::null and null_mut to all thin (including extern) types by SimonSapin...
source link: https://github.com/rust-lang/rust/pull/94954
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Contributor
SimonSapin commented on Mar 15
Fixes #93959
This change was accepted in https://rust-lang.github.io/rfcs/2580-ptr-meta.html
Note that this changes the signature of stable functions. The change should be backward-compatible, but it is insta-stable since it cannot (easily, at all?) be made available only through a #![feature(…)]
opt-in.
The RFC also proposed the same change for NonNull::dangling
, which makes sense it terms of its signature but not in terms of its implementation. dangling
uses align_of()
as an address. But what align_of()
should be for extern types or whether it should be allowed at all remains an open question.
This commit depends on #93977, which is not yet part of the bootstrap compiler. So #[cfg]
is used to only apply the change in stage 1+. As far a I know bounds cannot be made conditional with #[cfg]
, so the entire functions are duplicated. This is unfortunate but temporary.
Since this duplication makes it less obvious in the diff, the new definitions differ in:
- More permissive bounds (
Thin
instead of impliedSized
) - Different implementation
- Having
rustc_allow_const_fn_unstable(const_fn_trait_bound)
- Having
rustc_allow_const_fn_unstable(ptr_metadata)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK