-
Notifications
You must be signed in to change notification settings - Fork 891
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
Fix a possible double-borrow during event handling #1512
Fix a possible double-borrow during event handling #1512
Conversation
if let Some(event) = self.0.events.borrow_mut().pop_front() { | ||
// Make sure not to let the borrow_mut live during the next handle_event | ||
let event = { self.0.events.borrow_mut().pop_front() }; | ||
if let Some(event) = event { |
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 am new to Rust, but this fix looks like it shouldn't be necessary.
Is the borrow_mut
alive for the whole scope of the if let
?
PS: I am sure the fix is adequate. I am having a hard time understanding the issue and fix Rust wise.
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.
That's what I assumed also, which is why I ended up writing the bug in the first place 😛
I'd guess it has to do with the scope the value is alive for? Even if a value isn't used, I believe the drop is performed at the end of the scope it lives in. Therefore the old borrow lasted until the end of the if let
(or maybe even the outer block) even though it could have been dropped earlier.
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.
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to usersResolves #1476