rust-clippy/tests/ui/map_flatten.rs

61 lines
1.4 KiB
Rust
Raw Normal View History

#![warn(clippy::map_flatten)]
#![feature(result_flattening)]
2023-07-27 11:40:22 +00:00
//@no-rustfix
// issue #8506, multi-line
#[rustfmt::skip]
fn long_span() {
let _: Option<i32> = Some(1)
.map(|x| {
//~^ ERROR: called `map(..).flatten()` on `Option`
//~| NOTE: `-D clippy::map-flatten` implied by `-D warnings`
if x <= 5 {
Some(x)
} else {
None
}
})
.flatten();
2020-07-30 19:20:31 +00:00
let _: Result<i32, i32> = Ok(1)
.map(|x| {
//~^ ERROR: called `map(..).flatten()` on `Result`
if x == 1 {
Ok(x)
} else {
Err(0)
}
})
.flatten();
2020-07-30 19:20:31 +00:00
let result: Result<i32, i32> = Ok(2);
fn do_something() { }
let _: Result<i32, i32> = result
.map(|res| {
//~^ ERROR: called `map(..).flatten()` on `Result`
if res > 0 {
do_something();
Ok(res)
} else {
Err(0)
}
})
.flatten();
let _: Vec<_> = vec![5_i8; 6]
.into_iter()
.map(|some_value| {
//~^ ERROR: called `map(..).flatten()` on `Iterator`
if some_value > 3 {
Some(some_value)
} else {
None
}
})
.flatten()
.collect();
}
fn main() {
long_span();
}