-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add #[repr(transparent)]
to Path & PathBuf
#72841
Conversation
Given the vast number of impls on these two structs, it would be nearly impossible to have any other internal representation without removing any of these. Resolves #72838.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @hanna-kruppe (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @dtolnay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on #72838 (comment) it sounds like this is motivated by wanting to do unsafe { mem::transmute::<&PathBuf, &OsString>(pathbuf) }.capacity()
(and similar).
If so, I would prefer not to make this change. Note that repr(transparent) is not the same as permission to inspect or manipulate the internal representation of a type. That permission only exists if the field is also exposed as pub
. So I believe this change doesn't make what you want to do any more correct than before.
Understandable. Question time, though. Is there any better way to do what I want? The internal details are unstable, although I don't believe it would make sense to be implemented any other way at this point. A read-only field would be ideal, but that's not a thing in Rust proper. |
A way to e.g. read the capacity (or s/capacity/some_future_api/) of the OsString inside of PathBuf without PathBuf exposing the OsString or the capacity publicly? I don't know of a way but you could bring it up in #t-libs on zulip. You can transmute anyway but the correctness of that would be between you and the users of your crate. |
Given the vast number of impls on these two structs, it would be nearly
impossible to have any other internal representation without removing
any of these.
Resolves #72838.