-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix error message for mismatched types #41547
Fix error message for mismatched types #41547
Conversation
This addresses rust-lang#41425 by implementing the changes mentioned in the following comment: rust-lang#41425 (comment)
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (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. |
This adjusts several lines to be shorter than 100 characters.
// `break`, we want to call the `()` "expected" | ||
// since it is implied by the syntax. | ||
assert!(expression_ty.is_nil()); | ||
let (expected, found) = if label_expression_as_expected { | ||
(expression_ty, self.final_ty.unwrap_or(self.expected_ty)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you dropped half of a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the comment was meant to be deleted per #41425 (comment). Should I rephrase the remaining part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can leave the comment, or amend some text like "(Note not all force-units work this way.)"
15 | | } | ||
| |_^ expected (), found i32 | ||
| | ||
= note: expected type `i32` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are the note and label the other way around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not entirely sure as well. @nikomatsakis Should the label be reversed too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @arielb1. To fix that you have to change this line (part of fn coerce_inner()
, not found in the diff):
fcx.eq_types(true, cause, expression_ty, self.merged_ty())
to be something like this:
fcx.eq_types(label_expression_as_expected, cause, expression_ty, self.merged_ty())
That true
argument indicates that the a
value (first type) ought to be marked as "expected". That is no longer always true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for pointing this out!
@bors r+ |
📌 Commit c741bc8 has been approved by |
…sage, r=arielb1 Fix error message for mismatched types This addresses #41425 by implementing the changes mentioned in the following comment: #41425 (comment)
☀️ Test successful - status-appveyor, status-travis |
This addresses #41425 by implementing the changes mentioned in the
following comment:
#41425 (comment)