7

Fix FP on `if_then_some_else_none` when there is early return by dswij · Pull Re...

 3 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/7980
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Member

@xFrednet xFrednet left a comment

The implementation looks good to me.


For future reference: The example in the issue could in theory still use bool::then() and then call flatten on the result like this(playground)

 fn f2(b: bool, v: Option<()>) -> Option<()> {
    b.then(|| {
        v?;
        Some(())
    })
    .flatten()
}

However, this only works if the early return is also inside the return expression of function. I like this solution implemented in this PR. Just wanted to document it for future reference upside_down_face


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK