I see. If we modify my original example a bit:
let speaker: i32 = 42;
speaker.speak(); // OK
(&speaker).speak(); // type inference error
In the first case, i32 is unambiguously borrowed as i32. But in the second case &i32 can be borrowed as i32 or &i32 because both implement Display. In the original example, &str can be borrowed as str or &str, and the compiler can't figure out which I want.
Now I believe it makes sense. Still wish there were a generic way to take a type by value or by reference, for types which don't implement AsRef...
@EdmundsEcho, that's a good suggestion for a refactor, but as it happens I do not control the type T or the trait SomeTrait (i.e. they are from disjoint crates), so that would require someone else to impl<T> SomeTrait for Box<T>, impl<T> SomeTrait for Arc<T>, etc.
Edit: The trick is to impose a recursive trait bound
where T: std::borrow::Borrow<T> + std::fmt::Display. This matches types which implement the trait (Display) and requires that that the type actually received by the function can be borrowed in such a way that disambiguates betweenimpl Borrow<T> for Tandimpl Borrow<T> for &T.