Closed
Description
Given the following code:
struct Struct {
x: isize,
y: isize
}
fn main() {
match (Struct { x: 239, y: 240 }) {
// ignored field
Struct { x: unused, .. } => {}
}
}
The current output is:
warning: unused variable: `unused`
--> src/main.rs:9:21
|
9 | Struct { x: unused, .. } => {}
| ^^^^^^-
| |
| help: try removing the field
|
= note: `#[warn(unused_variables)]` on by default
warning: field `y` is never read
--> src/main.rs:3:5
|
1 | struct Struct {
| ------ field in this struct
2 | x: isize,
3 | y: isize
| ^
|
= note: `#[warn(dead_code)]` on by default
The suggestion is questionable because Struct { x: .. }
is not valid rust code, we should probably suggest removing the x:
as well..?
Errors of the code rustc suggested:
The following errors were reported:
error: `..` patterns are not allowed here
--> src/main.rs:9:22
|
9 | Struct { x: .. } => {}
| ^^
|
= note: only allowed in tuple, tuple struct, and slice patterns
error[E0027]: pattern does not mention field `y`
--> src/main.rs:9:9
|
9 | Struct { x: .. } => {}
| ^^^^^^^^^^^^^^^^^ missing field `y`
|
help: include the missing field in the pattern
|
9 | Struct { x: .., y } => {}
| ~~~~~
help: if you don't care about this missing field, you can explicitly ignore it
|
9 | Struct { x: .., .. } => {}
| ~~~~~~
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0027`.
Original diagnostics will follow.
Activity
chenyukang commentedon Dec 2, 2022
@rustbot claim
fix rust-lang#105028, Only suggest removing struct field from destruc…
Rollup merge of rust-lang#105174 - chenyukang:yukang/fix-105028-unuse…