Open
Description
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:
fn main() {
let option = MyOption::MySome(String::new());
option.take();
}
enum MyOption<T> {
MyNone,
MySome(T),
}
impl<T> MyOption<T> {
fn take(&mut self) -> Option<T> {
match self {
MyOption::MySome(value) => {
*self = MyOption::MyNone;
Some(value)
},
MyOption::MyNone => None,
}
}
}
(playground)
gives the following error message:
error[E0308]: mismatched types
--> src/main.rs:16:22
|
16 | Some(value)
| ^^^^^ expected type parameter, found &mut T
|
= note: expected type `T`
found type `&mut T`
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 of T
.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.