Skip to content

Commit 347e798

Browse files
committed
Fix match_single_binding suggestion introduced an extra semicolon
1 parent d822110 commit 347e798

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

clippy_lints/src/matches/match_single_binding.rs

+1-6
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;

tests/ui/match_single_binding.fixed

+13
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

+14
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,17 @@ fn issue_9575() {
148148
_ => println!("Needs curlies"),
149149
};
150150
}
151+
152+
#[allow(dead_code)]
153+
fn issue_9725(r: Option<u32>) {
154+
match r {
155+
x => match x {
156+
Some(_) => {
157+
println!("Some");
158+
},
159+
None => {
160+
println!("None");
161+
},
162+
},
163+
};
164+
}

tests/ui/match_single_binding.stderr

+26-1
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,30 @@ LL + println!("Needs curlies");
213213
LL ~ };
214214
|
215215

216-
error: aborting due to 14 previous errors
216+
error: this match could be written as a `let` statement
217+
--> $DIR/match_single_binding.rs:154:5
218+
|
219+
LL | / match r {
220+
LL | | x => match x {
221+
LL | | Some(_) => {
222+
LL | | println!("Some");
223+
... |
224+
LL | | },
225+
LL | | };
226+
| |_____^
227+
|
228+
help: consider using a `let` statement
229+
|
230+
LL ~ let x = r;
231+
LL + match x {
232+
LL + Some(_) => {
233+
LL + println!("Some");
234+
LL + },
235+
LL + None => {
236+
LL + println!("None");
237+
LL + },
238+
LL ~ };
239+
|
240+
241+
error: aborting due to 15 previous errors
217242

0 commit comments

Comments
 (0)