Skip to content

Commit af1e40a

Browse files
JarredAllenflip1995
andcommitted
Documentation suggestions from flip1995
Co-Authored-By: Philipp Krones <hello@philkrones.com>
1 parent e266ebc commit af1e40a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

clippy_lints/src/option_if_let_else.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
99

1010
declare_clippy_lint! {
1111
/// **What it does:**
12-
/// Detects people who use `if let Some(v) = ... { y } else { x }`
13-
/// when they could use `Option::map_or` or `Option::map_or_else`
14-
/// instead.
12+
/// Lints usage of `if let Some(v) = ... { y } else { x }` which is more
13+
/// idiomatically done with `Option::map_or` or `Option::map_or_else`.
1514
///
1615
/// **Why is this bad?**
17-
/// Using the dedicated function in the Option class is clearer and
16+
/// Using the dedicated functions of the Option type is clearer and
1817
/// more concise than an if let expression.
1918
///
2019
/// **Known problems:**
21-
/// Using `Option::map_or` (as the lint presently suggests) requires
20+
/// Using `Option::map_or` (as the lint currently suggests) requires
2221
/// it to compute the else value every function call, even if the
2322
/// value is unneeded. It might be better to use Option::map_or_else
2423
/// if the code is either very expensive or if it changes some state

tests/ui/option_if_let_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![warn(clippy::option_if_let_else)]
21
// run-rustfix
2+
#![warn(clippy::option_if_let_else)]
33

44
fn bad1(string: Option<&str>) -> (bool, &str) {
55
if let Some(x) = string {

0 commit comments

Comments
 (0)