Skip to content

"Multiple applicate methods in scope" error on unambiguous method call #18681

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
japaric opened this issue Nov 6, 2014 · 1 comment
Closed

Comments

@japaric
Copy link
Member

japaric commented Nov 6, 2014

STR

trait FooChar {
    fn foo(&self, char) {}
}

trait FooInt {
    fn foo(&self, int) {}
}

impl FooChar for char {}
impl FooInt for char {}

trait Bar<T> {
    fn bar(&self, T) {}
}

impl Bar<char> for char {}
impl Bar<int> for char {}

fn main() {
    'a'.foo('b');  //~ error: multiple applicable methods in scope
    'a'.bar('b');  // OK
}

Output

conflict.rs:20:9: 20:17 error: multiple applicable methods in scope [E0034]
conflict.rs:20     'a'.foo('b');  //~ error: multiple applicable methods in scope
                       ^~~~~~~~
conflict.rs:2:5: 2:24 note: candidate #1 is defined in the trait `FooChar`
conflict.rs:2     fn foo(&self, char) {}
                  ^~~~~~~~~~~~~~~~~~~
conflict.rs:6:5: 6:23 note: candidate #2 is defined in the trait `FooInt`
conflict.rs:6     fn foo(&self, int) {}
                  ^~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Version

rustc 0.13.0-dev (98958bcaf 2014-11-05 10:21:38 +0000)

I'm under the impression that 'a'.foo('b') should just work, although there are two traits that provide the foo method, it's clear from the signature of the method call that FooChar should be used. After all, it's possible to do something similar using multidispatch (the Bar trait)

cc @nikomatsakis

@nikomatsakis
Copy link
Contributor

I don't think this is expected to work. The way method selection works, it needs to be able to narrow to at least a specific trait, without considering the types of the arguments. In the case of FooChar vs FooInt, we can't narrow to a specific trait based solely on the receiver. (In the case of Bar, we can -- the Bar trait).

lnicola added a commit to lnicola/rust that referenced this issue Dec 16, 2024
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