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

Add version mismatch help message for unimplemented trait #66561

Merged
merged 3 commits into from
Nov 26, 2019

Conversation

TimoFreiberg
Copy link
Contributor

@TimoFreiberg TimoFreiberg commented Nov 19, 2019

Improves issue #22750

The error reporting for E0277 (the trait X is not implemented for Foo)
now checks whether Foo implements a trait with the same path as X,
which probably means that the programmer wanted to actually use only one
version of the trait X instead of the two.

Still open:

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2019
@@ -0,0 +1,21 @@
// aux-build:crate_a1.rs
// aux-build:crate_a2.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one new test for the case where the diagnostic is correct. Do we also want testcases that verify that the diagnostic is not emitted?
E.g. there exists a trait with same path but it's not implemented for the struct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative tests are always good to have, particularly because incorrect suggestions are sometimes worse than no suggestions. Can you create one for the case you mention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding a few cases:

  • A type that doesn't implement any of the two traits
  • A type that doesn't implement any of the two traits, but a different variant of the type implements the wrong trait
  • A type that doesn't implement any of the two traits, but a different variant of the type implements the correct trait

@cramertj
Copy link
Member

@bors r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned cramertj Nov 20, 2019
src/librustc/traits/error_reporting.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,21 @@
// aux-build:crate_a1.rs
// aux-build:crate_a2.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative tests are always good to have, particularly because incorrect suggestions are sometimes worse than no suggestions. Can you create one for the case you mention?

Issue rust-lang#22750
The error reporting for E0277 (the trait `X` is not implemented for `Foo`)
now checks whether `Foo` implements a trait with the same path as `X`,
which probably means that the programmer wanted to actually use only one
version of the trait `X` instead of the two.
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 25, 2019

📌 Commit 2a0292f has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2019
@bors
Copy link
Contributor

bors commented Nov 26, 2019

⌛ Testing commit 2a0292f with merge 0f6f66f...

bors added a commit that referenced this pull request Nov 26, 2019
Add version mismatch help message for unimplemented trait

Improves issue #22750

The error reporting for E0277 (the trait `X` is not implemented for `Foo`)
now checks whether `Foo` implements a trait with the same path as `X`,
which probably means that the programmer wanted to actually use only one
version of the trait `X` instead of the two.

Still open:
* the same diagnostic should be added for [the trait method case](#22750 (comment))
* Showing the real crate versions would be nice, but rustc currently doesn't have that information [according to Esteban](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/diagnostics.20for.20crate.20version.20mismatch/near/180572989)
@bors
Copy link
Contributor

bors commented Nov 26, 2019

☀️ Test successful - checks-azure
Approved by: estebank
Pushing 0f6f66f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 26, 2019
@bors bors merged commit 2a0292f into rust-lang:master Nov 26, 2019
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #66561!

Tested on commit 0f6f66f.
Direct link to PR: #66561

🎉 rustc-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).

@edmorley
Copy link
Contributor

Hi! :-) The diagnostic suggestion added here isn't being shown in my case - I don't know whether it comes under the things known to not be implemented, or whether this is unexpected - I've filed #89143.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants