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
I tried this code, simplified from the larger example.
use std::collections::HashMap;use std::borrow::Borrow;use std::hash::Hash;pubstructMyStruct<K>(HashMap<K,Vec<K>>);impl<K>MyStruct<K>whereK:Hash + Eq{pubfnremove<Q>(&mutself,key:&Q)whereQ:Hash + Eq + ?Sized,K:Borrow<Q>{ifletSome(val) = self.0.remove(key){for v in val {self.0.get_mut(&v).unwrap().clear();// works: self.0.get_mut::<K>(&v).unwrap().clear();}}}}
I expected to see this happen: it compiles successfully.
Instead, this happened: It complains that the argument to get_mut is of type &K rather than the expected type &Q. While this is true, it's irrelevant, as &K is a valid argument to that function. This can be shown by turbofishing the call.
I believe this is another instance of #24066 - while inferring the type parameter for the get_mut call, the compiler latches onto the superficially relevant K: Borrow<Q> bound from the where clause.
Uh oh!
There was an error while loading. Please reload this page.
I tried this code, simplified from the larger example.
I expected to see this happen: it compiles successfully.
Instead, this happened: It complains that the argument to
get_mut
is of type&K
rather than the expected type&Q
. While this is true, it's irrelevant, as&K
is a valid argument to that function. This can be shown by turbofishing the call.Meta
rustc --version --verbose
:Also verified with nightly via the playground.
Backtrace
The text was updated successfully, but these errors were encountered: