Uh oh!
There was an error while loading. Please reload this page.
[WIP] Remove various transmutes - #47005
Conversation
rust-highfive
commented
Dec 25, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
petrochenkov
commented
Dec 26, 2017
I don't know what is the official policy and half of the changed cases looks better with |
There was a problem hiding this comment.
This one in particular I don't know why transmute isn't the best way. We need some way to do the &[X] -> &NewType([X]) cast.
There was a problem hiding this comment.
This still performs the same cast, just without transmuting the fat pointer. Can you explain further why transmute would be preferred here?
bluss
commented
Dec 31, 2017
Yes, we want to set a good example and not use transmute, though I agree many of them look better with transmute; with transmute, we also have some size checking that the pointer casts don't have. So it's almost like we want better primitives that are transmute-like. Previous removal of them was in #14069 but there are frankly not many there that are worth bringing back, except transmute_lifetime, and whatever new ones we need. |
shepmaster
commented
Jan 6, 2018
Happy new year from triage, @nvzqz! A reminder that this is awaiting your feedback! |
bors
commented
Jan 6, 2018
☔ The latest upstream changes (presumably #47225) made this pull request unmergeable. Please resolve the merge conflicts. |
@bluss I'm of the opinion that I agree that some of these look better as transmutes but unless there's necessary size checks, alternatives should be considered. Proof I don't hate @shepmaster Happy new year ❤️ Edit: This is still a WIP. I'll update the title when I feel that this PR finishes accomplishing what I intend for it to. I've just been busy in my personal life. |
bluss
commented
Jan 7, 2018
@nvzqz Sure, I'm also partial to that. I don't really dislike these changes, but I hope we can find something even better for Rust than these myriads of double |
There was a problem hiding this comment.
This one is actually wrong — the original is tricky. self.addr.sun_path is an array and the transmute with explicit type is using the coercion from array to slice.
I am not actually sure if it's wrong. But I'll have to double check how this works with coercion here.
Reinterpreting &[u8] <-> &[c_char] seems like it should be a function.
There was a problem hiding this comment.
And the old target type was &[u8], in this code it is instead &[c_char]. They should switch places. Convert from c_char to u8.
There was a problem hiding this comment.
I see what you mean. Thanks a lot @bluss, you're awesome 👍🏻. Thanks for everything you do for this project. I'm make the appropriate changes tomorrow.
Fixes lifetime errors that occur when using the AsRef implementation.
shepmaster
commented
Jan 13, 2018
Heads up from triage, @bluss! Looks like there are new commits to be reviewed! |
| fn deref(&self) -> &'static str { | ||
| let l = INTERNER.strs.lock().unwrap(); | ||
| unsafe { mem::transmute::<&str, &'static str>(l.get(*self)) } | ||
| let s: &str = l.get(*self).as_ref(); |
There was a problem hiding this comment.
What's as_ref called on? If it's &String then you should remove .as_ref() and let it coerce.
There was a problem hiding this comment.
Same for all the other 5 cases in this file.
| unsafe { | ||
| mem::transmute(slice::from_raw_parts(0x1 as *const T, 0)) | ||
| let slice = slice::from_raw_parts(0x1 as *const T, 0); | ||
| &*(slice as *const [T] as *const Slice<T>) |
There was a problem hiding this comment.
This should be &*(mem::align_of::<T>() as *const [T; 0] as *const [T] as *const Slice<T>).
shepmaster
commented
Jan 26, 2018
Ping from triage @nvzqz ! We haven't heard from you in over a week; do you think you'll be able to respond to the feedback soon? |
shepmaster
commented
Feb 3, 2018
Thanks for the PR, @nvzqz ! Since we haven't heard from you in a few weeks, I'm going to go ahead and close this PR for now. Please feel free to reopen when you are able to address the last bit of feedback. |
This PR removes various transmutes that can either be replaced with casts or safe code.