-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Labels
A-SB-vs-TBTopic: Design questions where SB and TB are opposite sides of the design axisTopic: Design questions where SB and TB are opposite sides of the design axisA-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows)C-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions
Description
Currently, the following is illegal according to Stacked Borrows:
let val = [1u8, 2];
let ptr = &val[0] as *const u8;
let _val = unsafe { *ptr.add(1) };
The problem is that the cast to *const u8
creates a raw pointer that may only be used for the u8
it points to, not anything else. The most common case is to do &slice[0] as *const _
instead of slice.as_ptr()
.
This has lead to problems:
- rand did the
&slice[0]
thing. - Same for hashbrown.
Rc::into_raw
+Rc::from_raw
don't work well together because of this.- capnproto also used the
&slice[0]
pattern
Maybe this is too restrictive and raw pointers should be allowed to access their "surroundings"? I am not sure what exactly that would look like though. It would probably require having the raw pointer fully inherit all permissions from the reference it is created from.
I'll use this issue to collect such cases.
gnzlbg, comex, ecstatic-morse, oilaba, CeleritasCelery and 3 moreorzogc
Metadata
Metadata
Assignees
Labels
A-SB-vs-TBTopic: Design questions where SB and TB are opposite sides of the design axisTopic: Design questions where SB and TB are opposite sides of the design axisA-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)Topic: Related to the aliasing model (e.g. Stacked/Tree Borrows)C-open-questionCategory: An open question that we should revisitCategory: An open question that we should revisitS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions