-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Dereference of pointer does not end its life #6159
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
I don't think this is a bug. A pointer is still usable after being dereferenced, you're just copying out of the dereferenced location. You could dereference it again and copy out again. |
In this case though, the pointer isn't used again. Why would it be live? EDIT: Initially the failing case was 'let x = *self.x.get_x()', without the variable y that could be considered live until the end of the function. In that case it definitely should not be considered live. EDIT #2: Using 'let x; { x = *self.x.get_x() }' does fix the issue. |
In response to:
because the scope of |
Ah, okay, the variant where you do not pull out |
In response to this:
An even simpler variant on that fix is: let x = { *self.x.get_x() }; which as far as I can tell, also fixes your issue. @nikomatsakis is this handling of the results of sub-expressions by design, or is it a deficiency in the current borrow-check and/or lifetime semantics? |
I've edited the bug description as suggested by pnkfelix. |
Compiling this:
yields the error
The self pointer is considered loaned out from 'let x = *self.x.get_x()', even though it... isn't.
The text was updated successfully, but these errors were encountered: