Closed
Description
struct Point {
x: i32,
y: i32,
}
fn main() {
let points = vec!(Point { x: 1, y: 2 }, Point { x: 3, y: 4 });
let y_sum: i32 = points.iter()
.map(|Point { x, y }| y)
.sum();
println!("{}", y_sum);
}
gives this warning :
warning: unused variable: `x`
--> src\main.rs:10:23
|
10 | .map(|Point { x, y }| y)
| ^ help: consider using `_x` instead
|
= note: #[warn(unused_variables)] on by default
However, applying such changes gives these errors :
error[E0026]: struct `Point` does not have a field named `_x`
--> src\main.rs:10:23
|
10 | .map(|Point { _x, y }| y)
| ^^ struct `Point` does not have this field
error[E0027]: pattern does not mention field `x`
--> src\main.rs:10:15
|
10 | .map(|Point { _x, y }| y)
| ^^^^^^^^^^^^^^^ missing field `x`
error: aborting due to 2 previous errors
I think the warning should be replaced with something that works (like x:_
) or not issued at all.
$ rustc --version --verbose
rustc 1.30.1 (1433507eb 2018-11-07)
binary: rustc
commit-hash: 1433507eba7d1a114e4c6f27ae0e1a74f60f20de
commit-date: 2018-11-07
host: x86_64-pc-windows-msvc
release: 1.30.1
LLVM version: 8.0