-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Why does Pin::set take self by value? #57339
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This is what I implemented and what I intended when I implemented it, but I didn't notice the discrepancy with @withoutboats's stabilization report. If they feel that this should be changed, it seems worth discussing, otherwise I'm comfortable moving forward with it as-is. The choice here is whether or not to build-in reborrowing into the method or to require a call to |
Just to make sure I understand the implications, does the following code behave as I expect? use pin_utils::pin_mut;
fn main() {
let x = Foo { ... };
pin_mut!(x);
x.set(Foo { ... })
// Pin<&mut x> does not implement Copy because &mut _ is (obviously) not copyable
// So x has been consumed and there is no way to access the underlying value anymore...
} And if so, what is the intended use case for |
Oh, wait, I think I understand your earlier remark about let x = Foo { ... };
pin_mut!(x);
let x2 = x.as_mut();
x2.set(Foo { ... });
// At this point, x2 has been destroyed, but the old x borrow becomes usable again Coming from a world of pointers and references, it decidedly feels odd to need to manually reborrow like this in order to avoid losing access to the |
It does feel odd to need to manually reborrow, and its unfortunate that |
I see, if the plan is to enable reborrow semantics later on it does make more sense ! |
Is there a reason you would not want reborrow semantics? The current API is technically the most "broad," but if what it enables is useless (I can't think of a use), we could just backport a change to the API. |
(The discrepancy with the stabilization report was a mistake on my part I believe; I don't remember noting this and I didn't list it as a change to be made before stabilizing) |
Sorry, I worded my last comment very poorly. What I meant is, if the plan is to eventually give |
I was responding to the issue, not your last comment. I think it would be strictly better to make this change while we still can. |
@withoutboats I don't have any strong feelings either way. I'll open a PR to change and we can see if anyone opposes or otherwise merge it. |
Reborrow Pin<P> using &mut in `Pin::set` Fixes #57339. This makes it possible to call `.set` multiple times without using `.as_mut()` first to reborrow the pointer. r? @withoutboats cc @rust-lang/libs
Looking at https://doc.rust-lang.org/nightly/std/pin/struct.Pin.html, I see that Pin::set takes
self
by value. This is unlike the API that was proposed in the tracking issue #55766, which would take&mut self
instead, and I could not find a rationale for this discrepancy in the tracking issue.Is this intended? If not, you may want to fix this before the Pin stabilization actually hits beta/stable 😉
The text was updated successfully, but these errors were encountered: