-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
implement Entry API for SmallIntMap #17879
Conversation
pub fn entry<'a>(&'a mut self, key: uint) -> Entry<'a, V> { | ||
let self_ptr = self as *mut _; | ||
match self.find_mut(&key) { | ||
// FIXME: So, this is absolutely awful. We absolutely *do not* need a raw ptr for |
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.
Have you tried something like:
{
match self.find_mut(&key) {
Some(val) => return Occupied(...)
None => {}
}
}
Vacant(...)
EDIT: It doesn't work. I'm surprised the borrow "bleeds" out of the enclosing block.
EDIT EDIT: I think it's because the region of the returned expression becomes linked to that of the return value of the function, which is the same as that of self ('a
), which is linked to the region of the function body. This ends up extending the lifetime. Come to think of it, I think I've seen people complain about this before.
Your borrow checker pain seems to be issue #6393. The problem attempting to use return as a workaround is called out as a particularly tricky case. |
val: &'a mut V, | ||
// We only need this for `take`. Should never be null, and we'll only use it when | ||
// we we'll never touch `val` again. Totally safe, just lame that we need this. | ||
// The alternative would be doing the indexing on every op, which would make this API |
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.
Another alternative would be storing &'a mut Option<V>
, which would be totally safe but would require unwrapping the Option
.
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.
Still need the ref to decrement len :(
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.
What len is being decremented? SmallIntMap
doesn't cache the number of set elements.
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.
@gereeter Oh! You know, I just totally assumed. That makes the Option solution much more viable, though the unwraps are unsavoury.
r? @aturon |
I spent a few minutes trying to find a better way around the borrow checker here, but to no avail. This code also makes me sad, but at least it's all hidden behind the API. Someday we'll be able to do this better... |
4e436d1
to
71c2d73
Compare
Sorry about that. Fixed, squashed, and make checked. |
I don't understand the error that was spat out:
I didn't rebase to latest master, could something odd have changed with resolution? |
@gankro Method resolution has been in flux, so possibly? Definitely worth rebasing and seeing if you can reproduce. |
Rebased to master, still works. I'm at a loss. |
Is SmallIntMap really even worth having? It's basically just Vec. |
@reem I've been pushing for stuff to be pulled when we start stabilizing. SmallIntMap I could take or leave. It's pretty easy for a client to write safely, but also has low maintenance cost. Until then, I'm forced to assume it will stay. |
What's the point? It offers almost no added utility over |
71c2d73
to
361ec43
Compare
@reem It's easier to use than a |
Even if we decide not to stabilize it, we'd move it out to an external Cargo crate, so I think it's still worth making the API consistent with the other collections. |
@gankro I will try to take a look at this failure ASAP. |
Killing this while collections reform is on. |
The contents of this PR make me legit mad. I really hope that I'm just completely stupid tonight, and there's a way better way to do this. It doesn't help that this API is basically pointless to provide on SmallIntMap. But we've gotta provide a uniform interface, so...
yeah
😡