Skip to content
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

"multiple applicable methods in scope" error should list them #1946

Closed
brson opened this issue Mar 9, 2012 · 8 comments
Closed

"multiple applicable methods in scope" error should list them #1946

brson opened this issue Mar 9, 2012 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority

Comments

@brson
Copy link
Contributor

brson commented Mar 9, 2012

When calling a method and there are 'multiple applicable methods in scope' it's very hard to resolve the issue because the error doesn't tell you which implementations are causing the conflict.

@nikomatsakis
Copy link
Contributor

even better, it should tell you which import brought the method into scope.

@brson
Copy link
Contributor Author

brson commented Apr 23, 2013

The situation is better now:

/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:26:4: 26:15 error: multiple applicable methods in scope
/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:26     i.foo_it();
                                                                                ^~~~~~~~~~~
/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:21:19: 21:39 note: candidate #1 is `__extensions__::foo_it`
/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:21 impl Foo for int { fn foo_it(&self) { } }
                                                                                               ^~~~~~~~~~~~~~~~~~~~
/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:22:19: 22:39 note: candidate #2 is `__extensions__::foo_it`
/home/brian/dev/rust3/src/test/compile-fail/multiple-methods-in-scope.rs:22 impl Bar for int { fn foo_it(&self) { } }
                                                                                               ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

@brson
Copy link
Contributor Author

brson commented Apr 23, 2013

The error reporting still could be a lot better: "candidate #1 is the implementation of Foo for int", "note: candidate #1 imported here"

@brson
Copy link
Contributor Author

brson commented Apr 23, 2013

Removing from 1.0

@emberian
Copy link
Member

emberian commented Aug 5, 2013

Visiting for triage, nothing to add

@catamorphism
Copy link
Contributor

Low, not 1.0

@japaric
Copy link
Member

japaric commented Nov 18, 2014

The error message is much better now:

use foo::Foo;
use bar::Bar;

mod foo {
    pub trait Foo {
        fn baz(&self) {}
    }
}

mod bar {
    pub trait Bar {
        fn baz(&self) {}
    }
}

struct Quux;

#[cfg(not(error))]
impl Quux {
    fn baz(&self) {}
}

impl foo::Foo for Quux {}
impl bar::Bar for Quux {}

fn main() {
    Quux.baz();
}
$ rustc --cfg error 1946.rs
1946.rs:27:10: 27:15 error: multiple applicable methods in scope [E0034]
1946.rs:27     Quux.baz();
                    ^~~~~
1946.rs:23:1: 23:26 note: candidate #1 is defined in an impl of the trait `foo::Foo` for the type `Quux`
1946.rs:23 impl foo::Foo for Quux {}
           ^~~~~~~~~~~~~~~~~~~~~~~~~
1946.rs:24:1: 24:26 note: candidate #2 is defined in an impl of the trait `bar::Bar` for the type `Quux`
1946.rs:24 impl bar::Bar for Quux {}
           ^~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

It tells you the full path of the conflicting traits.

I think the compiler could even suggest using UFCS to disambiguate: "note: use Foo::baz(&Quux) or Bar::baz(&Quux) to disambiguate the method call"

I've got one question tough, if Quux has an inherent baz() method, then the compiler uses that method and ignores the methods provided by Foo and Bar:

$ rustc 1946.rs && echo OK
OK

Not sure if that's intended, perhaps it should throw a warning?

cc @nikomatsakis

@steveklabnik
Copy link
Member

Yup, we get good error messages on this today. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority
Projects
None yet
Development

No branches or pull requests

6 participants