You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a Drop impl preventing , so the error should at least mention it. But the implicit reborrow self.url hides this error with a '*self.url' does not live long enough one.
Changing the impl to
impl<'a>S<'a>{fnfinish(self) -> &'amutString{let p = self.url;
p
}}
gives a better error message: self.urlcannot move out of type "S<'_>", which implements the "Drop" trait.
To be even more clear: the error here isn't about the illegality of moving out of a struct with a destructor, because the code is not doing any such move.
What the code is doing is borrowing into the interior of a struct with a destructor, and that borrow outlives the lifetime of the struct. Thus the struct's Drop impl might mutably access the borrowed (i.e. aliased) state, violating the rule that all such &mut-accesses are unaliased.
That's not to say that the given error message cannot be improved.
In particular, it might be better if it said something like:
15 | self.url
| ^^^^^^^^ borrow extends past lifetime of value
16 | }
| - `self` dropped here while `self.url` still borrowed
|
= note: `self` is of type `S<'_>`, which implements `Drop`; thus
dropping `self` requires exclusive access to `self.url`.
Activity
pnkfelix commentedon Sep 11, 2018
assigning to self, hoping to investigate this week
pnkfelix commentedon Sep 14, 2018
(to be clear, even an explicit reborrow would produce the error message that is being deemed inferior here...)
pnkfelix commentedon Sep 17, 2018
To be even more clear: the error here isn't about the illegality of moving out of a struct with a destructor, because the code is not doing any such move.
What the code is doing is borrowing into the interior of a struct with a destructor, and that borrow outlives the lifetime of the struct. Thus the struct's
Drop
impl might mutably access the borrowed (i.e. aliased) state, violating the rule that all such&mut
-accesses are unaliased.That's not to say that the given error message cannot be improved.
In particular, it might be better if it said something like:
pnkfelix commentedon Sep 17, 2018
Okay I think I have a patch to fix this. And it seems like it improves some of our other diagnostics elsewhere. Will post PR soonish.
&mut
aliasing during Drop #54310Auto merge of #54310 - pnkfelix:issue-52059-report-borrow-drop-confli…