Open
Description
Normally, inherent methods are given precedence over all trait methods, so that there is no ambiguity.
However, this behavior does not appear to be implemented for trait object types:
trait Foo {
fn f(&self) { }
}
impl Foo {
fn f(&self) { }
}
impl Foo for i32 { }
struct Bar;
impl Bar {
fn f(&self) { }
}
impl Foo for Bar { }
fn main() {
let x: &Foo = &42i32;
x.f();
let bar: &Bar = &Bar;
bar.f();
}
What's worse, UFCS does not allow for specifying that you want the inherent method, because Foo::f(x)
in this code will remain ambiguous. In general, UFCS isn't designed to support disambiguating to inherent methods because inherent methods are supposed to always take precedence.