Skip to content
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

Merged
merged 4 commits into from
Apr 11, 2020

Conversation

ryanisaacg
Copy link
Contributor

@ryanisaacg ryanisaacg commented Mar 16, 2020

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Resolves #1476

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 {
Copy link
Contributor

@filnet filnet Mar 16, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@filnet filnet Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanisaacg
Copy link
Contributor Author

@Osspial Any idea why CI is failing? Same for #1511

@ryanisaacg ryanisaacg marked this pull request as ready for review April 11, 2020 19:20
@ryanisaacg ryanisaacg merged commit a8e777a into rust-windowing:master Apr 11, 2020
@ryanisaacg ryanisaacg deleted the fix-double-borrow branch April 11, 2020 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

panic: already borrowed: BorrowMutError
2 participants