This commit is contained in:
togami2864 2021-11-16 02:53:35 +09:00
parent cd5781648a
commit 300282c09a
4 changed files with 16 additions and 19 deletions

View File

@ -11,7 +11,8 @@ use rustc_span::symbol::sym;
use super::OPTION_MAP_OR_NONE;
use super::RESULT_MAP_OR_INTO_OPTION;
/// The expression inside a closure may or may not have surrounding braces
// The expression inside a closure may or may not have surrounding braces
// which causes problems when generating a suggestion.
fn reduce_unit_expression<'a>(
cx: &LateContext<'_>,
expr: &'a hir::Expr<'_>,

View File

@ -4,16 +4,14 @@
fn main() {
let opt = Some(1);
let bar = |_| {
Some(1)
};
let bar = |_| Some(1);
// Check `OPTION_MAP_OR_NONE`.
// Single line case.
let _ :Option<i32> = opt.map(|x| x + 1);
let _: Option<i32> = opt.map(|x| x + 1);
// Multi-line case.
#[rustfmt::skip]
let _ :Option<i32> = opt.map(|x| x + 1);
let _: Option<i32> = opt.map(|x| x + 1);
// function returning `Option`
let _ :Option<i32> = opt.and_then(bar);
let _: Option<i32> = opt.and_then(bar);
}

View File

@ -4,18 +4,16 @@
fn main() {
let opt = Some(1);
let bar = |_| {
Some(1)
};
let bar = |_| Some(1);
// Check `OPTION_MAP_OR_NONE`.
// Single line case.
let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
// Multi-line case.
#[rustfmt::skip]
let _ :Option<i32> = opt.map_or(None, |x| {
let _: Option<i32> = opt.map_or(None, |x| {
Some(x + 1)
});
// function returning `Option`
let _ :Option<i32> = opt.map_or(None, bar);
let _: Option<i32> = opt.map_or(None, bar);
}

View File

@ -1,24 +1,24 @@
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
--> $DIR/option_map_or_none.rs:13:26
--> $DIR/option_map_or_none.rs:11:26
|
LL | let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
--> $DIR/option_map_or_none.rs:16:26
--> $DIR/option_map_or_none.rs:14:26
|
LL | let _ :Option<i32> = opt.map_or(None, |x| {
LL | let _: Option<i32> = opt.map_or(None, |x| {
| __________________________^
LL | | Some(x + 1)
LL | | });
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
--> $DIR/option_map_or_none.rs:20:26
--> $DIR/option_map_or_none.rs:18:26
|
LL | let _ :Option<i32> = opt.map_or(None, bar);
LL | let _: Option<i32> = opt.map_or(None, bar);
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
error: aborting due to 3 previous errors