Open
Description
What it does
This lint will use a rest pattern (..
), instead of ignoring values with _
when destructuring structs and enums.
I'm suggesting to only do this for _
, and leave as they are the cases where the values are named and prefixed with an underscore.
Lint Name
ignored_field_when_destructuring
Category
style
Advantage
- This reduces noise and makes it more obvious which fields are relevant, especially when there are many ignored values.
Drawbacks
- This will prevent a compilation error if additional fields are added to the struct. Some programmers may want that error to remind them to do something with the newly added fields.
Example
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 0, y: 0 };
let Point { x, y: _ } = origin;
println!("x is {}", x);
Could be written as:
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 0, y: 0 };
let Point { x, .. } = origin;
println!("x is {}", x);