-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
PathBuf: replace transmuting by accessor functions #124410
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
Turns out when this transmute was originally added 9 years ago, pub struct Wtf8Buf {
bytes: Vec<u8>
} So, it wasn't A good lesson in why we should not use transmutes to circumvent field privacy. |
FWIW I did not review whether the things A better fix may be to add a private |
998fedb
to
c47978a
Compare
lovely.. i wonder how many sussy transmutes there are in other places... |
@bors r=Nilstrieb |
@bors rollup |
…strieb PathBuf: replace transmuting by accessor functions The existing `repr(transparent)` was anyway insufficient as `OsString` was not `repr(transparent)`. And furthermore, on Windows it was blatantly wrong as `OsString` wraps `Wtf8Buf` which is a `repr(Rust)` type with 2 fields: https://github.com/rust-lang/rust/blob/51a7396ad3d78d9326ee1537b9ff29ab3919556f/library/std/src/sys_common/wtf8.rs#L131-L146 So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through. Fixes rust-lang#124409
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#124341 (resolve: Remove two cases of misleading macro call visiting) - rust-lang#124383 (Port run-make `--print=native-static-libs` to rmake.rs) - rust-lang#124391 (`rustc_builtin_macros` cleanups) - rust-lang#124408 (crashes: add more tests) - rust-lang#124410 (PathBuf: replace transmuting by accessor functions) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - rust-lang#124341 (resolve: Remove two cases of misleading macro call visiting) - rust-lang#124383 (Port run-make `--print=native-static-libs` to rmake.rs) - rust-lang#124391 (`rustc_builtin_macros` cleanups) - rust-lang#124408 (crashes: add more tests) - rust-lang#124410 (PathBuf: replace transmuting by accessor functions) r? `@ghost` `@rustbot` modify labels: rollup
@RalfJung @Nilstrieb If it's exposing mutable reference to the buffer, i think |
Rollup merge of rust-lang#124410 - RalfJung:path-buf-transmute, r=Nilstrieb PathBuf: replace transmuting by accessor functions The existing `repr(transparent)` was anyway insufficient as `OsString` was not `repr(transparent)`. And furthermore, on Windows it was blatantly wrong as `OsString` wraps `Wtf8Buf` which is a `repr(Rust)` type with 2 fields: https://github.com/rust-lang/rust/blob/51a7396ad3d78d9326ee1537b9ff29ab3919556f/library/std/src/sys_common/wtf8.rs#L131-L146 So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through. Fixes rust-lang#124409
Yes, see what I wrote above: #124410 (comment) Feel free to open an issue to track a proper cleanup here. I just have the time for a basic soundness fix right now, not the time to make it nice. |
Hmm, it would have been sufficient to set the field to |
The existing
repr(transparent)
was anyway insufficient asOsString
was notrepr(transparent)
. And furthermore, on Windows it was blatantly wrong asOsString
wrapsWtf8Buf
which is arepr(Rust)
type with 2 fields:rust/library/std/src/sys_common/wtf8.rs
Lines 131 to 146 in 51a7396
So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through.
Fixes #124409