-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking Issue for offset_from_unsigned (feature ptr_sub_ptr) #95892
Copy link
Copy link
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Milestone
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feature gate:
#![feature(ptr_sub_ptr)]&#![feature(const_ptr_sub_ptr)]This is a tracking issue for the
<*const _>::sub_ptr&<*mut _>::sub_ptrmethods.This is the produces-
usizeversion ofoffset_from, the same way thataddandsubare the takes-usizeversions ofoffset.It turns out that people almost always actually know which pointer is greater than which when doing this operation, and would rather a
usizeinstead of anisize-- every use ofoffset_fromin the library was followed withas usizein practice. So like how.add(d)greatly improved code compared to needing.offset(d as isize), being able to useptr.sub_ptr(origin)instead ofptr.offset_from(origin) as usizeis also a major improvement. And Miri can check the unsafety better, too, since if you get the order wrong it'll detect that, unlike happens with theas usizeapproach.This also tracks the
constness of operations, though with #92980 stabilizingoffset_frombeingconst, this beingconstis likely uncontroversial.Public API
Steps / History
sub_ptron pointers (theusizeversion ofoffset_from) #95837NonNullmethod to this gate Stabilizenon_null_convenience#124498(const_)ptr_sub_ptr#137121Unresolved Questions
addandsubmethods, but there might be another name that would be more evocative for people Addsub_ptron pointers (theusizeversion ofoffset_from) #95837 (comment)