Skip to content

Method selection with by-val self may choose the wrong implementor #15335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexcrichton opened this issue Jul 2, 2014 · 4 comments
Closed

Comments

@alexcrichton
Copy link
Member

trait Foo {
    fn foo(self) { println!("default") }
}

impl Foo for Box<Foo> {
    fn foo(self) { println!("overridden") }
}

impl Foo for int {
    fn foo(self) { println!("int") }
}

fn main() {
    let f = box 1i as Box<Foo>;
    f.foo();
}

I am under the impression that this test should print overridden, not int.

Nominating.

@alexcrichton
Copy link
Member Author

This was altered recently as part of #15242 (by accident I presume)

@pcwalton
Copy link
Contributor

pcwalton commented Jul 2, 2014

This is the correct behavior with the system we have today. Object methods such as the second method are considered inherent methods, while methods arising from implementations of a trait such as the first method are considered extension methods. Inherent methods are checked before extension methods and override them.

Perhaps we want to change this behavior, but this is, as stated, not a bug.

@alexcrichton
Copy link
Member Author

Sounds like this is working as intended, surprising!

@alexcrichton
Copy link
Member Author

We can revisit this if it becomes more of a problem.

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 13, 2023
…, r=lnicola

feat: skip checking token tree count for include! macro call

fix rust-lang#15335 rust-lang#15648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants