Fix match_single_binding suggestion introduced an extra semicolon

This commit is contained in:
alex-semenyuk 2022-11-07 10:51:52 +03:00
parent d822110d3b
commit 3b6bbf7d16
4 changed files with 58 additions and 14 deletions

View File

@ -31,19 +31,11 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
};
// Do we need to add ';' to suggestion ?
match match_body.kind {
ExprKind::Block(block, _) => {
if let ExprKind::Block(block, _) = match_body.kind {
// macro + expr_ty(body) == ()
if block.span.from_expansion() && cx.typeck_results().expr_ty(match_body).is_unit() {
snippet_body.push(';');
}
},
_ => {
// expr_ty(body) == ()
if cx.typeck_results().expr_ty(match_body).is_unit() {
snippet_body.push(';');
}
},
}
let mut applicability = Applicability::MaybeIncorrect;

View File

@ -133,3 +133,16 @@ fn issue_9575() {
println!("Needs curlies");
};
}
#[allow(dead_code)]
fn issue_9725(r: Option<u32>) {
let x = r;
match x {
Some(_) => {
println!("Some");
},
None => {
println!("None");
},
};
}

View File

@ -148,3 +148,17 @@ fn issue_9575() {
_ => println!("Needs curlies"),
};
}
#[allow(dead_code)]
fn issue_9725(r: Option<u32>) {
match r {
x => match x {
Some(_) => {
println!("Some");
},
None => {
println!("None");
},
},
};
}

View File

@ -213,5 +213,30 @@ LL + println!("Needs curlies");
LL ~ };
|
error: aborting due to 14 previous errors
error: this match could be written as a `let` statement
--> $DIR/match_single_binding.rs:154:5
|
LL | / match r {
LL | | x => match x {
LL | | Some(_) => {
LL | | println!("Some");
... |
LL | | },
LL | | };
| |_____^
|
help: consider using a `let` statement
|
LL ~ let x = r;
LL + match x {
LL + Some(_) => {
LL + println!("Some");
LL + },
LL + None => {
LL + println!("None");
LL + },
LL ~ };
|
error: aborting due to 15 previous errors