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

Explicitly suggest dereferencing when type mismatch differs by reference only #34562

Closed
kornelski opened this issue Jun 29, 2016 · 0 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@kornelski
Copy link
Contributor

kornelski commented Jun 29, 2016

Type mismatch error could be more specific and friendlier if it had special handling of case where the compiler found &type, but expected type.

error: mismatched types [--explain E0308]

^ expected enum std::option::Option, found &-ptr

The current message is correct and (with notes) it's possible to understand it, but "expected type, found &-ptr" obscures what type has actually been found (#25426), and makes it sound like a worse mismatch than it really is.

note: expected type std::option::Option<_>
note: found type &std::option::Option<foo>

Notes for this error make the problem clear, but they're repeating the first part of the message, so it's already using four lines to say one thing. Listing both types requires me to compare them and spot the difference myself.

I hope there are no weird edge cases in this situation, and the compiler could simplify the message by proposing solution outright. Something like:

error: value must be dereferenced
Expected std::option::Option<_>. Use *var instead of var to dereference &std::option::Option<foo>.

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 1, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jul 25, 2017
bors added a commit that referenced this issue Sep 23, 2017
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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants