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 compilation error for get_mut_or_tagged_slot function #4

Merged
merged 3 commits into from
Oct 14, 2019
Merged

Fix compilation error for get_mut_or_tagged_slot function #4

merged 3 commits into from
Oct 14, 2019

Conversation

kalabukdima
Copy link
Contributor

Build in stable branch was failing with an error:

error[E0505]: cannot move out of `_` because it is borrowed
   --> src/slab.rs:460:13
    |
454 |     fn get_mut_or_tagged_slot(&mut self, id: Id<T>) -> Result<&mut T, Option<&mut TaggedSlot<T>>> {
    |                               - let's call the lifetime of this reference `'1`
...
457 |                 slot: Slot::Occupied { ref mut value },
    |                                        ------------- borrow of value occurs here
458 |                 tag,
459 |             }) if tag == id.tag => Ok(value),
    |                                    --------- returning this value requires that borrow lasts for `'1`
460 |             tagged_slot => Err(tagged_slot),
    |             ^^^^^^^^^^^ move out of value occurs here

Explanation of a similar problem can be found here.
This is the least messy fix that I could come up with.

Interestingly, there is no such problem with a get_or_tagged_slot function only because multiple non-mutable borrows of the same value are allowed.

BTW, should I bump the package version with this PR?

@kalabukdima kalabukdima changed the title Fix compilation error for get_mut_or_tagged_slot function Fix compilation error for get_mut_or_tagged_slot function Oct 13, 2019
Copy link
Owner

@cristicbz cristicbz left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR, this looks like a regression-from-stable-to-stable to me! I suggested an alternative which seems to avoid the unreachable!, still pulling out the if-guard and occupied-check into separate matches. I think it's nicer---see what you think and let me know.

Also, yeah, it'd be great if you could also bump up the version number, so I can publish the new version, thanks!

src/slab.rs Outdated Show resolved Hide resolved
@cristicbz cristicbz merged commit a5cd57d into cristicbz:master Oct 14, 2019
@cristicbz
Copy link
Owner

Awesome, thanks! On the "double runtime check" didn't mean perf-wise, just meant style-wise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants