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();
}
https://play.rust-lang.org/?gist=7d4534a5d973249c66244b9affa03199&version=stable&mode=debug
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.
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:
https://play.rust-lang.org/?gist=7d4534a5d973249c66244b9affa03199&version=stable&mode=debug
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.