Skip to content

Commit 2e856fa

Browse files
committed
add test for block comment and add note to description
1 parent d7e7234 commit 2e856fa

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

clippy_lints/src/matches/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ declare_clippy_lint! {
3838
/// Checks for matches with a single arm where an `if let`
3939
/// will usually suffice.
4040
///
41+
/// This intentionally does not lint if there are comments
42+
/// inside of the other arm, so as to allow the user to document
43+
/// why having another explicit pattern with an empty body is necessary,
44+
/// or because the comments need to be preserved for other reasons.
45+
///
4146
/// ### Why is this bad?
4247
/// Just readability – `if let` nests less than a `match`.
4348
///

tests/ui/single_match.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,18 @@ mod issue8634 {
237237
},
238238
}
239239
}
240+
241+
fn block_comment(x: Result<i32, SomeError>) {
242+
match x {
243+
Ok(y) => {
244+
println!("Yay! {y}");
245+
},
246+
Err(_) => {
247+
/*
248+
let's make sure that this also
249+
does not lint block comments.
250+
*/
251+
},
252+
}
253+
}
240254
}

tests/ui/single_match.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,18 @@ mod issue8634 {
295295
},
296296
}
297297
}
298+
299+
fn block_comment(x: Result<i32, SomeError>) {
300+
match x {
301+
Ok(y) => {
302+
println!("Yay! {y}");
303+
},
304+
Err(_) => {
305+
/*
306+
let's make sure that this also
307+
does not lint block comments.
308+
*/
309+
},
310+
}
311+
}
298312
}

0 commit comments

Comments
 (0)