mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
40b558af76
add more test cases with `match`; minor fixes in message output regarding review feedback
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
#![deny(clippy::bind_instead_of_map)]
|
|
#![allow(clippy::blocks_in_conditions)]
|
|
|
|
pub fn main() {
|
|
let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
|
|
let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) });
|
|
|
|
let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
|
|
let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) });
|
|
|
|
let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() });
|
|
let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) });
|
|
|
|
hard_example();
|
|
macro_example();
|
|
}
|
|
|
|
fn hard_example() {
|
|
Some("42").map(|s| {
|
|
if {
|
|
if s == "43" {
|
|
return 43;
|
|
}
|
|
s == "42"
|
|
} {
|
|
return 45;
|
|
}
|
|
match s.len() {
|
|
10 => 2,
|
|
20 => {
|
|
if foo() {
|
|
return {
|
|
if foo() {
|
|
return 20;
|
|
}
|
|
println!("foo");
|
|
3
|
|
};
|
|
}
|
|
20
|
|
},
|
|
40 => 30,
|
|
_ => 1,
|
|
}
|
|
});
|
|
}
|
|
|
|
fn foo() -> bool {
|
|
true
|
|
}
|
|
|
|
macro_rules! m {
|
|
() => {
|
|
Some(10)
|
|
};
|
|
}
|
|
|
|
fn macro_example() {
|
|
let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) });
|
|
let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) });
|
|
}
|