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.