-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
struct S(u32, Vec<i32>);
fn foo(x: &S) {
match x {
S(& (mut y), v) => {
}
}
}
The current output is:
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
--> src/lib.rs:5:11
|
4 | match x {
| - this expression has type `&S`
5 | S(& (mut y), v) => {
| ^^^^^^^^^ expected `u32`, found reference
|
= note: expected type `u32`
found reference `&_`
help: consider removing `&` from the pattern
|
5 - S(& (mut y), v) => {
5 + S(mut y), v) => {
|
Note that the suggestion is wrong, it removes the (
but left in the matching )
. Applying that suggestion leads to invalid code:
struct S(u32, Vec<i32>);
fn foo(x: &S) {
match x {
S(mut y), v) => {
}
}
}
It should instead suggest
5 - S(& (mut y), v) => {
5 + S(mut y, v) => {
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.