-
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
Make pointer
field of Pin
private
#119615
Conversation
As the fix-me comment suggested, use the macro hygiene of macros 2.0 to access the field in the `pin` macro. Therefore, the field can be made private.
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Back when this macro was added, @danielhenrymantilla did originally want to use a macro 2.0, but if I remember it correctly, it was decided that relying on such a macro was not good and that it should use a macro_rules with a hack instead. |
What does |
library/core/src/pin.rs
Outdated
@@ -1246,5 +1237,5 @@ pub macro pin($value:expr $(,)?) { | |||
// | |||
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension | |||
// for more info. | |||
$crate::pin::Pin::<&mut _> { pointer: &mut { $value } } | |||
Pin { pointer: &mut { $value } } |
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.
Removal of turbofish type is orthogonal to field privacy / hygiene, and technically allows for code such as let p: Pin<*mut _> = pin!(...);
(letting a coërcion happen on the pointer: ...
assignment).
Since this whole thing is already quite tricky/subtle, let's not risk unnecessary flexibility (which appears to be unsound
Pin { pointer: &mut { $value } } | |
Pin::<&mut _> { pointer: &mut { $value } } |
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.
I've readded this and added a comment explaining why it should not be removed.
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.
I wonder if I should also add a test for this case in this PR, so that others cannot stumble over the same thing.
Well, it's going to show |
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
I sometimes compile the expanded code to get better source line information etc. and to my understanding I can't easily make it compile anymore then by adding the internal feature flag? Not a too big issue but just came to my mind. |
r? @Nilstrieb Perhaps you remember which team / group made the decision referenced here:
|
I went through the discussion and it looks like this was a libs-api team decision in a meeting: #93176 (comment) |
☔ The latest upstream changes (presumably #119722) made this pull request unmergeable. Please resolve the merge conflicts. |
I noticed today that there's also a comment in // Skip suggestions for unstable public fields (for example `Pin::pointer`) The example should probably be omitted. Apart from |
I don't think we're supposed to use full macro 2.0 hygiene in a public macro yet. cc @petrochenkov |
Considering #119562 is merged, macros 2.0 hygiene isn't ready yet, and the temporary lifetime rfc work progressing towards a solution for the |
This PR is an alternative to #119562.
By using the macro hygiene of macros 2.0 inside the
pin
macro, thepointer
field ofPin
does no longer need to be public. Hiding it avoids the issue outlined in #119562, against which a regression test is added.