I rely on the compiler to tell me when generic bounds on my types/impls are insufficient and which trait constraints are missing, but the compiler never tells me when my generics are over-constrained.
Is there a tool for finding generics with constraints that are unneeded by any part of the implementation?
For example, if I had some wrapper around a HashMap
and a custom impl for get
:
struct MyWrapper<K, V> {
inner: HashMap<K, V>,
}
impl<K: Eq + Hash + Serialize, V> MyWrapper<K, V> {
pub fn my_get(&self, key: &K) -> Option<&V> {
self.inner.get(key)
}
}
And let's say HashMap
requires the key K
to be Eq + Hash
, but not Serialize
, then it would be nice to run some tool that says, "Excuse me, but you're over-constraining your impl and you could remove Serialize
if you'd like".
Are there any tools like this?