You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a type with a lifetime parameter as key for im::HashMap, read-only methods like get will not accept keys with shorter lifetimes. For example:
When compiling this, the compiler complains that key1 and key2 do not live long enough; it requires that they are borrowed for 'static, even though it seems get should only need the key being available for the duration of the function call. I believe this is due to im::HashMap being invariant over its key parameter. The same example compiles and works as expected using std::collections::HashMap.
Would it be possible to make im::HashMap covariant over the key type? Or is there a reason this is not possible?
The text was updated successfully, but these errors were encountered:
This has the (desired) side effect of making containers covariant over
their input type, so we also add some assertions to ensure that this
doesn't regress.
Fixesbodil#196.
jneem
linked a pull request
May 1, 2022
that will
close
this issue
When using a type with a lifetime parameter as key for
im::HashMap
, read-only methods likeget
will not accept keys with shorter lifetimes. For example:When compiling this, the compiler complains that
key1
andkey2
do not live long enough; it requires that they are borrowed for 'static, even though it seemsget
should only need the key being available for the duration of the function call. I believe this is due to im::HashMap being invariant over its key parameter. The same example compiles and works as expected usingstd::collections::HashMap
.Would it be possible to make im::HashMap covariant over the key type? Or is there a reason this is not possible?
The text was updated successfully, but these errors were encountered: