-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Bad diagnostic for match ergonomics #70047
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Diagnostic on nightly:
|
Do you have any suggestions as to what the error message should say in the best of worlds? |
I imagine some of these confusing errors are really due to #64586. I think we should try to fix that one. |
I think a "bigger" error message explaining what the compiler did and what the user needs to do precisely here might be required. |
@GuillaumeGomez That's not really actionable as a specification I could go implement though. Could you try to take the diagnostic on nightly and adjust it to your preference? |
@Centril: Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of `self.0` which is behind a mutable reference
--> src/main.rs:13:15
|
13 | match *self {
| ^^^^^ help: consider borrowing here: `&*self`
14 | MyOption::MySome(value) => {
| -----
| |
| data moved here
| move occurs because `value` has type `T`, which does not implement the `Copy` trait |
I did some quick investigation of strategies to fix this issue. Unfortunately, the way the type checker is setup today, |
This completely goes against the primary purpose of the match ergonomics: making pattern matching borrows simpler. :-/ I don't know how to improve things efficiently considering how complex this would be... |
What about checking in which context (i.e. expected type) the auto-ref value is used and say something like:
? |
Current output:
|
This is a reopening of #51743 to not lose track of the diagnostic issue which still remains to this day.
Match ergonomics can create quite confusing errors.
For instance:
(playground)
gives the following error message:
This error message is not even helping the user to figure out what the problem is.
Here, it's like if value was of type
&mut T
instead ofT
.The text was updated successfully, but these errors were encountered: