Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Add #[repr(transparent)] to Path & PathBuf #72841

wants to merge 1 commit into from

Conversation

jhpratt
Copy link
Member

@jhpratt jhpratt commented May 31, 2020

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.

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.
@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2020
@Elinvynia Elinvynia added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2020
@Dylan-DPC-zz
Copy link

r? @dtolnay

@dtolnay dtolnay added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 12, 2020
Copy link
Member

@dtolnay dtolnay left a 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.

@jhpratt
Copy link
Member Author

jhpratt commented Jun 12, 2020

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.

@dtolnay
Copy link
Member

dtolnay commented Jun 12, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add #[repr(transparent)] to PathBuf
6 participants