So I've been trying to implement a simple hash-consing library. I am trying to match the speed of my C implementation, and as the current rust version using fxHashMap was still slower, I decided to give Hashbrown a go. Unfortunately, even though it should be a direct replacement for fxHashMap, I get these "dropped here while still borrowed" errors now. I have managed to reduce my problem to the short listing below (playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=bef6e35df318356a3880f37ef23a7b40):
use hashbrown::HashMap;
use std::cell::RefCell;
type BrokenTable<'a> = HashMap<&'a i32, &'a i32>;
struct NonSense<'a> {
exps: RefCell<BrokenTable<'a>>,
x: Box<i32>
}
impl<'a> NonSense<'a> {
fn new() -> NonSense<'a> {
NonSense {
exps: RefCell::<BrokenTable::<'a>>::new(BrokenTable::<'a>::default()),
x: Box::new(1)
}
}
fn foo(&'a self) -> &'a i32 {
&self.x
}
}
fn test() {
let n = NonSense::new();
let i = n.foo();
println!("{}", i);
}
Is this a bug? Am I doing something wrong? Any suggestions to replace fxHashMap? I'd be very happy to have someone's input on this.