Skip to content

Trait method has higher precedence than inherent method if autoref is required for the inherent method #68826

Closed
@jplatte

Description

@jplatte

I was very surprised when I found the following outputs "trait method" (playground):

struct Struct;

impl Struct {
    fn foo(&self) {
        println!("inherent method")
    }
}

pub trait Foo {
    fn foo(self);
}

impl Foo for Struct {
    fn foo(self) {
        println!("trait method")
    }
}

fn main() {
    Struct.foo();
}

Up until now I always thought that an inherent method always takes precedence over a trait method of the same name. Is that not true in this case / is this behaviour intended?

This came up in yew, which defined an inherent try_into (now renamed) with a type parameter that would start producing errors about unexpected type parameters when TryInto (or stdweb::unstable::TryInto) was brought into scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions