This lint I don't quite agree with, and I realize opinions will differ on this.
Existing code in removed (red) and the proposed change by clippy in added (green) lines:
// clear edges without touching the free list
for node in &mut self.g.nodes {
- if let Some(_) = node.weight {
+ if node.weight.is_some() {
node.next = [EdgeIndex::end(), EdgeIndex::end()];
}
}
- if let None = node_weight {
+ if node_weight.is_none() {
return None;
}
etc with similar examples.
I think that using if let is fundamental to Rust, is general, works with any enum and is just as easy to understand as the alternative. I prefer general over Option-specific methods.
Advantages of Option methods:
Disadvantages of Option methods
I don't have a strong opinion either way. I just do what clippy says
We could make it a restriction lint, but then I'd also like to see the opposite lint.
Side note:
- if let None = node_weight {
+ if node_weight.is_none() {
return None;
}
shouldn't that simply be node_weight?;
shouldn't that simply be node_weight?;
I'd like to see a lint for that. :)
Please suggest replacing o.is_some() with o.iter().count() == 1 and o.is_none() with o.iter().count() == 0.
I think that using collections is fundamental to Rust. This method is general, works with any collection and is just as easy to understand as the alternative. I prefer general over Option-specific methods.
No trolling, please.
Most helpful comment
Please suggest replacing
o.is_some()witho.iter().count() == 1ando.is_none()witho.iter().count() == 0.I think that using collections is fundamental to Rust. This method is general, works with any collection and is just as easy to understand as the alternative. I prefer general over Option-specific methods.