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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,24 @@ impl<T> IdSlab<T> {
}

fn get_mut_or_tagged_slot(&mut self, id: Id<T>) -> Result<&mut T, Option<&mut TaggedSlot<T>>> {
match self.slots.get_mut(id.index as usize) {
Some(&mut TaggedSlot {
slot: Slot::Occupied { ref mut value },
let tagged_slot = self.slots.get_mut(id.index as usize).ok_or(None)?;
kalabukdima marked this conversation as resolved.
Show resolved Hide resolved
match *tagged_slot {
TaggedSlot {
slot: Slot::Occupied { .. },
tag,
}) if tag == id.tag => Ok(value),
tagged_slot => Err(tagged_slot),
} if tag == id.tag => {
// We can not just return the inner value here because `*tagged_slot`
// would be considered borrowed until the end of the entire function.
// But it needs to be borrowed in the next match handle.
// That's why we have to re-match it.
match *tagged_slot {
TaggedSlot {
slot: Slot::Occupied { ref mut value }, ..
} => Ok(value),
_ => unreachable!(),
}
},
_ => Err(Some(tagged_slot)),
}
}

Expand Down