2022-03-21 01:11:22 -05:00
|
|
|
#![warn(clippy::map_flatten)]
|
2021-08-01 04:47:29 -05:00
|
|
|
#![feature(result_flattening)]
|
2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix
|
2022-03-21 01:11:22 -05:00
|
|
|
// issue #8506, multi-line
|
|
|
|
#[rustfmt::skip]
|
|
|
|
fn long_span() {
|
|
|
|
let _: Option<i32> = Some(1)
|
|
|
|
.map(|x| {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `map(..).flatten()` on `Option`
|
|
|
|
//~| NOTE: `-D clippy::map-flatten` implied by `-D warnings`
|
2022-03-21 01:11:22 -05:00
|
|
|
if x <= 5 {
|
|
|
|
Some(x)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.flatten();
|
2020-07-30 14:20:31 -05:00
|
|
|
|
2022-03-21 01:11:22 -05:00
|
|
|
let _: Result<i32, i32> = Ok(1)
|
|
|
|
.map(|x| {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `map(..).flatten()` on `Result`
|
2022-03-21 01:11:22 -05:00
|
|
|
if x == 1 {
|
|
|
|
Ok(x)
|
|
|
|
} else {
|
|
|
|
Err(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.flatten();
|
2020-07-30 14:20:31 -05:00
|
|
|
|
2022-03-21 01:11:22 -05:00
|
|
|
let result: Result<i32, i32> = Ok(2);
|
|
|
|
fn do_something() { }
|
|
|
|
let _: Result<i32, i32> = result
|
|
|
|
.map(|res| {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `map(..).flatten()` on `Result`
|
2022-03-21 01:11:22 -05:00
|
|
|
if res > 0 {
|
|
|
|
do_something();
|
|
|
|
Ok(res)
|
|
|
|
} else {
|
|
|
|
Err(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.flatten();
|
|
|
|
|
|
|
|
let _: Vec<_> = vec![5_i8; 6]
|
|
|
|
.into_iter()
|
|
|
|
.map(|some_value| {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `map(..).flatten()` on `Iterator`
|
2022-03-21 01:11:22 -05:00
|
|
|
if some_value > 3 {
|
|
|
|
Some(some_value)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.flatten()
|
|
|
|
.collect();
|
|
|
|
}
|
2021-08-01 04:47:29 -05:00
|
|
|
|
2022-03-21 01:11:22 -05:00
|
|
|
fn main() {
|
|
|
|
long_span();
|
2018-09-21 02:26:38 -05:00
|
|
|
}
|