Skip to content

Commit 268c4dd

Browse files
committed
Fix match_single_binding suggestion introduced an extra semicolon
1 parent e8c2357 commit 268c4dd

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

clippy_lints/src/matches/match_single_binding.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
3838
snippet_body.push(';');
3939
}
4040
},
41-
_ => {
42-
// expr_ty(body) == ()
43-
if cx.typeck_results().expr_ty(match_body).is_unit() {
44-
snippet_body.push(';');
45-
}
46-
},
41+
_ => {},
4742
}
4843

4944
let mut applicability = Applicability::MaybeIncorrect;
@@ -76,7 +71,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
7671
Some(AssignmentExpr::Local { span, pat_span }) => (
7772
span,
7873
format!(
79-
"let {} = {};\n{}let {} = {snippet_body}",
74+
"let {} = {};\n{}let {} = {snippet_body};",
8075
snippet_with_applicability(cx, bind_names, "..", &mut applicability),
8176
snippet_with_applicability(cx, matched_vars, "..", &mut applicability),
8277
" ".repeat(indent_of(cx, expr.span).unwrap_or(0)),

tests/ui/match_single_binding.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ fn issue_9575() {
133133
println!("Needs curlies");
134134
};
135135
}
136+
137+
#[allow(dead_code)]
138+
fn issue_9725(r: Option<u32>) {
139+
let x = r;
140+
match x {
141+
Some(_) => {
142+
println!("Some");
143+
},
144+
None => {
145+
println!("None");
146+
},
147+
};
148+
}

tests/ui/match_single_binding.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ fn issue_9575() {
149149
};
150150
}
151151

152-
fn _f(r: Option<u32>) {
153-
let _t = match r {
152+
#[allow(dead_code)]
153+
fn issue_9725(r: Option<u32>) {
154+
match r {
154155
x => match x {
155156
Some(_) => {
156157
println!("Some");

tests/ui/match_single_binding.stderr

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ LL | | };
147147
help: consider using a `let` statement
148148
|
149149
LL ~ let Point { x, y } = coords();
150-
LL + let product = x * y
150+
LL + let product = x * y;
151151
|
152152

153153
error: this match could be written as a `let` statement
@@ -213,56 +213,30 @@ LL + println!("Needs curlies");
213213
LL ~ };
214214
|
215215

216-
error: this let-binding has unit value
217-
--> $DIR/match_single_binding.rs:153:5
218-
|
219-
LL | / let _t = match r {
220-
LL | | x => match x {
221-
LL | | Some(_) => {
222-
LL | | println!("Some");
223-
... |
224-
LL | | },
225-
LL | | };
226-
| |______^
227-
|
228-
= note: `-D clippy::let-unit-value` implied by `-D warnings`
229-
help: omit the `let` binding
230-
|
231-
LL ~ match r {
232-
LL + x => match x {
233-
LL + Some(_) => {
234-
LL + println!("Some");
235-
LL + },
236-
LL + None => {
237-
LL + println!("None");
238-
LL + },
239-
LL + },
240-
LL + };
241-
|
242-
243216
error: this match could be written as a `let` statement
244-
--> $DIR/match_single_binding.rs:153:5
217+
--> $DIR/match_single_binding.rs:154:5
245218
|
246-
LL | / let _t = match r {
219+
LL | / match r {
247220
LL | | x => match x {
248221
LL | | Some(_) => {
249222
LL | | println!("Some");
250223
... |
251224
LL | | },
252225
LL | | };
253-
| |______^
226+
| |_____^
254227
|
255228
help: consider using a `let` statement
256229
|
257230
LL ~ let x = r;
258-
LL + let _t = match x {
231+
LL + match x {
259232
LL + Some(_) => {
260233
LL + println!("Some");
261234
LL + },
262235
LL + None => {
263236
LL + println!("None");
264237
LL + },
265-
LL + };
238+
LL ~ };
266239
|
267240

268-
error: aborting due to 16 previous errors
241+
error: aborting due to 15 previous errors
242+

0 commit comments

Comments
 (0)