about summary refs log tree commit diff
path: root/tests/rustdoc-js-std/parser-errors.js
diff options
context:
space:
mode:
authorCatherine Flores <catherine.3.flores@gmail.com>2024-11-13 00:08:36 +0000
committerGitHub <noreply@github.com>2024-11-13 00:08:36 +0000
commitb829d53c1996efb07995296c9fa5cb979d7bfb8b (patch)
tree73b9239dc286ba0238205a3aa7004ac3deb853a1 /tests/rustdoc-js-std/parser-errors.js
parentf58088b23eee1cb1afefc3207adbd184ee8d8346 (diff)
parent89210d7c5afb0e42b0b1e092b388c912761671e5 (diff)
downloadrust-b829d53c1996efb07995296c9fa5cb979d7bfb8b.tar.gz
rust-b829d53c1996efb07995296c9fa5cb979d7bfb8b.zip
New lint: `unnecessary_map_or` (#11796)
Closes https://github.com/rust-lang/rust-clippy/issues/10118

This lint checks `map_or` method calls to check if they can be
consolidated down to something simpler and/or more readable.

For example, the code
```rs
let x = Some(5);
x.map_or(false, |n| n == 5)
```

can be rewritten as
```rs
let x = Some(5);
x == Some(5)
```

In addition, when the closure is more complex, the code can be altered
from, say,
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.map_or(false, |n| n == [5])
```
into
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.is_some_and(|n| n == [5])
```

This lint also considers cases where the `map_or` can be chained with
other method calls, and accommodates accordingly by adding extra
parentheses as needed to the suggestion.

changelog: add new lint `unnecessary_map_or`
Diffstat (limited to 'tests/rustdoc-js-std/parser-errors.js')
0 files changed, 0 insertions, 0 deletions