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

Rework method disambiguation error to use structured suggestions #62922

Closed
estebank opened this issue Jul 24, 2019 · 1 comment
Closed

Rework method disambiguation error to use structured suggestions #62922

estebank opened this issue Jul 24, 2019 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Taken from #62921 (comment)

#62921 will extend the amount of times we display the disambiguated syntax in cases where multiple traits with the method being called is displayed in the following way:

error[E0034]: multiple applicable items in scope
  --> $DIR/method-ambig-two-traits-from-impls2.rs:15:5
   |
LL |     AB::foo();
   |     ^^^^^^^ multiple `foo` found
   |
note: candidate #1 is defined in an impl of the trait `A` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:7:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
   = help: to disambiguate the method call, write `A::foo(...)` instead
note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:11:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
   = help: to disambiguate the method call, write `B::foo(...)` instead

It'd be a good idea to take a hard look at this and come up with better output that hopefully is as easy to understand while also incorporating structured suggestions. Sadly, given the current diagnostic machinery, suggestions are shown always at the end, which wouldn't let us show the suggestions interleaved with the notes. The closest we could get is something like the following:

error[E0034]: multiple applicable items in scope
  --> $DIR/method-ambig-two-traits-from-impls.rs:15:11
   |
LL |     AB {}.foo();
   |           ^^^ multiple `foo` found
   |
note: candidate #1 is defined in an impl of the trait `A` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:7:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:11:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
help: disambiguate the method call to a specific trait:
  --> $DIR/method-ambig-two-traits-from-impls.rs:15:4
   |
LL |     A::foo(AB {})
   |     ^^^^^^^^^^^^^
LL |     B::foo(AB {})
   |     ^^^^^^^^^^^^^

It looks a bit too verbose, but that might be ok.

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Jul 24, 2019
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 5, 2019
@estebank
Copy link
Contributor Author

Current output

error[E0034]: multiple applicable items in scope
  --> $DIR/method-ambig-two-traits-from-impls2.rs:15:5
   |
LL |     AB::foo();
   |     ^^^^^^^ multiple `foo` found
   |
note: candidate #1 is defined in an impl of the trait `A` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:7:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
  --> $DIR/method-ambig-two-traits-from-impls2.rs:11:5
   |
LL |     fn foo() {}
   |     ^^^^^^^^
help: disambiguate the method call for candidate #1
   |
LL |     A::foo();
   |     ^^^^^^
help: disambiguate the method call for candidate #2
   |
LL |     B::foo();
   |     ^^^^^^

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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant