Skip to content

Show detailed expected/found types in error message when trait paths are the same #89633

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

Merged
merged 2 commits into from
Oct 10, 2021

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Oct 7, 2021

Fixes #65230.

Issue solved by this PR

trait T {
    type U;
    fn f(&self) -> Self::U;
}

struct X<'a>(&'a mut i32);

impl<'a> T for X<'a> {
    type U = &'a i32;
    fn f(&self) -> Self::U {
        self.0
    }
}

fn main() {}

Compiler generates the following note:

note: ...so that the types are compatible
  --> test.rs:10:28
   |
10 |       fn f(&self) -> Self::U {
   |  ____________________________^
11 | |         self.0
12 | |     }
   | |_____^
   = note: expected `T`
              found `T`

This note is not useful since the expected type and the found type are the same.

How this PR solve the issue

When the expected type and the found type are exactly the same in string representation, the note falls back to the detailed string representation of trait ref:

note: ...so that the types are compatible
  --> test.rs:10:28
   |
10 |       fn f(&self) -> Self::U {
   |  ____________________________^
11 | |         self.0
12 | |     }
   | |_____^
   = note: expected `<X<'a> as T>`
              found `<X<'_> as T>`

So that a user can notice what was different between the expected one and the found one.

@rust-highfive
Copy link
Contributor

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 7, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rhysd rhysd force-pushed the issue-65230 branch 2 times, most recently from 3af5075 to 493ca46 Compare October 7, 2021 18:56
@rust-log-analyzer

This comment has been minimized.

@rhysd
Copy link
Contributor Author

rhysd commented Oct 8, 2021

I believe this PR is ready for review.

@joshtriplett
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2021
@bors
Copy link
Collaborator

bors commented Oct 9, 2021

⌛ Trying commit 7b9ddbd with merge 241eecf4e768114fe5702e365e7f003c1ada0208...

@bors
Copy link
Collaborator

bors commented Oct 9, 2021

☀️ Try build successful - checks-actions
Build commit: 241eecf4e768114fe5702e365e7f003c1ada0208 (241eecf4e768114fe5702e365e7f003c1ada0208)

@rust-timer
Copy link
Collaborator

Queued 241eecf4e768114fe5702e365e7f003c1ada0208 with parent f875143, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (241eecf4e768114fe5702e365e7f003c1ada0208): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2021
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 9, 2021

📌 Commit 7b9ddbd has been approved by petrochenkov

@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 Oct 9, 2021
@bors
Copy link
Collaborator

bors commented Oct 9, 2021

⌛ Testing commit 7b9ddbd with merge c63fbaa9799dba29b73feb023d15c0cd8a4873f8...

@rust-log-analyzer

This comment has been minimized.

@bors

This comment has been minimized.

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

rhysd commented Oct 9, 2021

Thanks to CI, I found error messages change when -Zborrowck=mir is specified. I'll fix some test cases.

because previous test does not cause the expected error message when
`-Z borrowck=mir`.
@rhysd
Copy link
Contributor Author

rhysd commented Oct 9, 2021

@petrochenkov I updated the test to pass with -Z borrowck=mir. Would you review this again? I confirmed it passed with the following command locally:

./x.py test ./src/test/ui/issues/issue-65230.rs --compare-mode nll

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 10, 2021

📌 Commit 9211bee has been approved by petrochenkov

@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 Oct 10, 2021
@bors
Copy link
Collaborator

bors commented Oct 10, 2021

⌛ Testing commit 9211bee with merge 68dfa07...

@bors
Copy link
Collaborator

bors commented Oct 10, 2021

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 68dfa07 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 10, 2021
@bors bors merged commit 68dfa07 into rust-lang:master Oct 10, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 10, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (68dfa07): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

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.

Compiler should not omit associated type in compile error message
8 participants