Could we allow _ type placeholders in fn signatures of trait impls?
I understand that type inference is not desired on fn signatures in general, but for a trait impl there is no ambiguity. The types must match the trait declaration exactly, but sometimes this can be annoying to actually write out.
For a small example, this is the real BitAnd for HashSet:
impl<'a, 'b, T, S> BitAnd<&'b HashSet<T, S>> for &'a HashSet<T, S>
where T: Eq + Hash + Clone,
S: BuildHasher + Default
{
type Output = HashSet<T, S>;
fn bitand(self, rhs: &HashSet<T, S>) -> HashSet<T, S> {
self.intersection(rhs).cloned().collect()
}
}
I would usually write -> Self::Output for consistency, even though thatās a little longer in this case. Thereās no way that I know to do similar for the RHS type parameter though. But my idea is that perhaps we could let these be implicit:
fn bitand(self, rhs: _) -> _
Thereās no ambiguity here for the compiler, since it must match the BitAnd trait anyway. Itās left up to the programmer whether this pseudo-inference is clear, just like choosing whether to use type annotations in let bindings.
Maybe that example is too simple, but Iāve definitely felt at times that Iām needlessly repeating myself with complex types in trait impls.