-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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();
}
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.
stepancheg, hcpl, jplatte and cramertj
Metadata
Metadata
Assignees
Labels
A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.