Clippy lints / Style
Clippy lint · Style · checked with Clippy 0.1.99
clippy::result_map_or_into_option: Checks for usage of _.map_or(None, Some)
What it meansChecks for usage of _.map_or(None, Some). It is in the style group and warns by default.
Does it matter?
Readability, this can be written more concisely as _.ok().
Code that works but is not idiomatic Rust. Warns by default.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
assert_eq!(Some(1), r.map_or(None, Some));
Write this instead
assert_eq!(Some(1), r.ok());
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::result_map_or_into_option)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
result_map_or_into_option = "allow"One run
cargo clippy -- -A clippy::result-map-or-into-optionThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for usage of _.map_or(None, Some).
Why is this bad?
Readability, this can be written more concisely as
_.ok().
Example
assert_eq!(Some(1), r.map_or(None, Some));
Use instead:
assert_eq!(Some(1), r.ok());
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- needless_returnunneeded `return` statement
- new_without_defaultChecks for public types with a pub fn new() -> Self method and no implementation of Default
- len_zeroChecks for getting the length of something via .len() just to compare to zero, and suggests using .is_empty() where applicable
- redundant_patternthe `y @ _` pattern can be written as just `y`
- redundant_pattern_matchingLint for redundant pattern matching over Result, Option, std::task::Poll, std::net::IpAddr or bools
- redundant_static_lifetimesconstants have by default a `'static` lifetime
- result_unit_errthis returns a `Result<_, ()>`
- same_item_pushit looks like the same item is being pushed into this `Vec`
- self_named_constructorsconstructor `foo` has the same name as the type
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::needless_returnunneeded `return` statementRead it next →Did this answer your question?