rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.5k stars 1.55k forks source link

Suggest replacing pattern matching with `map` or `map_err` #8436

Open lkts opened 2 years ago

lkts commented 2 years ago

What it does

This is in some way an extension to redundant_pattern_matching lint. The lint flags pattern matching that can be trivially converted to map or map_err invocations.

Lint Name

extend redundant_pattern_matching or prefer_map_over_pattern_match

Category

style

Advantage

Drawbacks

Depending on the code base this lint can be very intrusive.

Example

Could be written as:

let foo = some_result_returning_fn().map(some_fn);

Could be written as:

let foo = some_option_returning_fn().map(some_fn);

Could be written as:

let foo = some_option_returning_fn().map_err(some_fn);
giraffate commented 2 years ago

It would be better to improve the manual_map.