Assist to turn `match` into `matches!` invocation
Given a 2-arm match that evaluates to a boolean we should offer an assist/lint diagnostic to turn it into the equivalent matches! invocation.
match scrutinee {
Some(val) if val.cond() => true,
_ => false,
}
// should become
matches!(scrutinee, Some(val) if val.cond());
We should also easily tell if it needs inversion, that is
match scrutinee {
Some(val) if val.cond() => false,
_ => true,
}
// should become (note the leading !)
!matches!(scrutinee, Some(val) if val.cond());
Making this an assist is probably simpler, and we can always upgrade it to a lint afterwards.
Can i pick this up? @Veykril
Sure. The assist should be placed in a new file at https://github.com/rust-lang/rust-analyzer/tree/master/crates/ide-assists/src/handlers I think and then registered at https://github.com/rust-lang/rust-analyzer/blob/4f2a67b26feba72dd9ae0ad0d36a2b36652cc68c/crates/ide-assists/src/lib.rs#L193
@bjorn3 Thank you, I would like to mention one thing, I have recently started learning Rust (few weeks back), So I might take a little while to complete this.
No problem. If you have any questions feel free to ask here or on the rust-lang zulip (https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer).
@neel-desh @bjorn3 May I work on it?
@pocket7878 hey go ahead.