2016-05-17 13:01:31 +00:00
|
|
|
struct Dog {
|
|
|
|
name: String,
|
|
|
|
age: u32,
|
|
|
|
}
|
|
|
|
|
don't suggest erroneous trailing comma after `..`
In #76612, suggestions were added for missing fields in
patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the
last field. This resulted in the "if you don't care about missing
fields" suggestion to recommend code with a trailing comma after the
field ellipsis (`..,`), which is actually not legal ("`..` must be at
the end and cannot have a trailing comma")!
Incidentally, the doc-comment on `error_unmentioned_fields` was using
`you_cant_use_this_field` as an example field name (presumably
copy-paste inherited from the description of Issue #76077), but
the present author found this confusing, because unmentioned fields
aren't necessarily unusable.
The suggested code in the diff this commit introduces to
`destructuring-assignment/struct_destructure_fail.stderr` doesn't
work, but it didn't work beforehand, either (because of the "found
reserved identifier `_`" thing), so you can't really call it a
regression; it could be fixed in a separate PR.
Resolves #78511.
2021-01-16 23:41:52 +00:00
|
|
|
|
2016-05-17 13:01:31 +00:00
|
|
|
fn main() {
|
|
|
|
let d = Dog { name: "Rusty".to_string(), age: 8 };
|
|
|
|
|
|
|
|
match d {
|
2020-09-11 20:47:33 +00:00
|
|
|
Dog { age: x } => {} //~ ERROR pattern does not mention field `name`
|
|
|
|
}
|
don't suggest erroneous trailing comma after `..`
In #76612, suggestions were added for missing fields in
patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the
last field. This resulted in the "if you don't care about missing
fields" suggestion to recommend code with a trailing comma after the
field ellipsis (`..,`), which is actually not legal ("`..` must be at
the end and cannot have a trailing comma")!
Incidentally, the doc-comment on `error_unmentioned_fields` was using
`you_cant_use_this_field` as an example field name (presumably
copy-paste inherited from the description of Issue #76077), but
the present author found this confusing, because unmentioned fields
aren't necessarily unusable.
The suggested code in the diff this commit introduces to
`destructuring-assignment/struct_destructure_fail.stderr` doesn't
work, but it didn't work beforehand, either (because of the "found
reserved identifier `_`" thing), so you can't really call it a
regression; it could be fixed in a separate PR.
Resolves #78511.
2021-01-16 23:41:52 +00:00
|
|
|
match d {
|
|
|
|
// trailing comma
|
|
|
|
Dog { name: x, } => {} //~ ERROR pattern does not mention field `age`
|
|
|
|
}
|
|
|
|
match d {
|
|
|
|
// trailing comma with weird whitespace
|
|
|
|
Dog { name: x , } => {} //~ ERROR pattern does not mention field `age`
|
|
|
|
}
|
2020-09-11 20:47:33 +00:00
|
|
|
match d {
|
|
|
|
Dog {} => {} //~ ERROR pattern does not mention fields `name`, `age`
|
2016-05-17 13:01:31 +00:00
|
|
|
}
|
|
|
|
}
|