-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Containing transmutes on slices and other representations. #6790
Comments
+1. Note that the first part (add abstractions) can be done even without the lint, and then just enforced via code review. |
This moves the raw struct layout of closures, vectors, boxes, and strings into a new `unstable::raw` module. This is meant to be a centralized location to find information for the layout of these values. As safe method, `unwrap`, is provided to convert a rust value to its raw representation. Unsafe methods to convert back are not provided because they are rarely used and too numerous to write an implementation for each (not much of a common pattern). This is progress on #6790. I tried to get a nice interface for a trait to implement in the raw module, but I was unable to come up with one. The hard part is that there are so many different directions to go from one way to another that it's difficult to find a pattern to follow to implement a trait with. Someone else might have some better luck though.
Triage: #7986 gave us A quick glance over the results of unsafe {
cast::transmute(Slice {
data: ptr::mut_offset(p, start as int) as *T,
len: (end - start) * sys::nonzero_size_of::<T>()
})
} which is far batter than it was (named fields), but not quite as self-contained as a single function. (Also, I imagine that many reviewers don't know about |
Closing, I think that |
or_fun_call: fix suggestion for `or_insert(vec![])` fixes rust-lang#6748 changelog: or_fun_call: fix suggestion for `or_insert(vec![])` on `std::collections::hash_map::Entry` or `std::collections::btree_map::Entry`
Right now a few places in the code base make assumptions about the internal representations of things like
&[T]
or other types that stand for internal representation details, mostly to implement low-level operations in unsafe blocks. For example you could see code like this:This is fine as long as the internal representation of those things doesn't change, but will wreak random havoc if something changes (for example as result of the implementation of the Dynamic types proposal, or a change to the way
&str
handles its hidden trailing byte)To improve on this situation, I think the following needs to be done for all build-in 'special' types like
&[T]
,&str
,char
etc:std::unstable
for the underlying representation. It would contain things likestruct SliceRep<T> { buf: *T, len:uint }
orstruct CharRep { v: uint }
.transmute
-like functions from/to those types. All low level work and casts to representations would then have to happen through the functions in the corresponding modules, where the warnings get explicitly disabled with an attribute.The canonical warn-free way to write
my_slice
would then become something like this:The text was updated successfully, but these errors were encountered: