6

Github Implement new lint: if_then_some_else_none by magurotuna · Pull Request #...

 3 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/6859
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

Contributor

bors commented 10 days ago

@giraffate can now approve this pull request

let cond_snip = utils::snippet(cx, cond.span, "[condition]");

let arg_snip = utils::snippet(cx, then_arg.span, "");

Comment on lines

85 to 86

giraffate 9 days ago

Collaborator

Can test codes like below be added? Using macro, the suggested code may be broken, so it would be better to use the method like snippet_with_macro_callsite.

    let _ = if matches!(true, true) {
        println!("true!");
        Some(matches!(true, false))
    } else {
        None
    };

Additionally, can test codes like below be added? The parenthesis isn't considered, so the suggested codes seem not to work.

    let x = Some(5);
    let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });

let cond_snip = utils::snippet(cx, cond.span, "[condition]");

let arg_snip = utils::snippet(cx, then_arg.span, "");

let help = format!(

"consider using `bool::then` like: `{}.then(|| {{ /* snippet */ {} }})`",

giraffate 9 days ago

Collaborator

If then block has no statements, it would be better to remove the placeholder like /* snippet */.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK