hashbrown icon indicating copy to clipboard operation
hashbrown copied to clipboard

Lifetime of input (key) to HashMap::get() gets entanged w/ that of its output (value)

Open zeenix opened this issue 4 years ago • 2 comments
trafficstars

This issue I filed against std also applies to hashbrown::HashMap. You can use the exact same code in there, replacing the HashMap use line and reproduce the issue. The problem is likely that lifetimes are not specified for HashMap::get arguments so rustc thinks the passed key's lifetime is somehow associated with that of self.

If that's the correct diagnoses, I'll hopefully provide a PR for both hashbrown and std soon.

zeenix avatar Dec 27 '20 16:12 zeenix

This feels like a compiler bug to me: the get function definition should return a value with the same lifetime as &self.

Amanieu avatar Dec 27 '20 20:12 Amanieu

This feels like a compiler bug to me: the get function definition should return a value with the same lifetime as &self.

It's very much possible. I did a bit of research but no matter what lifetimes I assign to all the functions in the chain, it doesn't help. :shrug:

zeenix avatar Dec 27 '20 20:12 zeenix