Skip to content

Do not suggest replacing simple if let Some(_) / None with methods #2353

@bluss

Description

@bluss

This lint I don't quite agree with, and I realize opinions will differ on this.

Lint link: https://rust-lang-nursery.github.io/rust-clippy/v0.0.177/index.html#if_let_redundant_pattern_matching

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-needs-discussionStatus: Needs further discussion before merging or work can be started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions