2019-08-15 20:56:27 +00:00
|
|
|
#![warn(clippy::suspicious_map)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = (0..3).map(|x| x + 2).count();
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: this call to `map()` won't have an effect on the call to `count()`
|
2021-03-25 18:29:11 +00:00
|
|
|
|
|
|
|
let f = |x| x + 1;
|
|
|
|
let _ = (0..3).map(f).count();
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: this call to `map()` won't have an effect on the call to `count()`
|
2021-03-25 18:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn negative() {
|
|
|
|
// closure with side effects
|
|
|
|
let mut sum = 0;
|
|
|
|
let _ = (0..3).map(|x| sum += x).count();
|
|
|
|
|
|
|
|
// closure variable with side effects
|
|
|
|
let ext_closure = |x| sum += x;
|
|
|
|
let _ = (0..3).map(ext_closure).count();
|
|
|
|
|
|
|
|
// closure that returns unit
|
|
|
|
let _ = (0..3)
|
|
|
|
.map(|x| {
|
|
|
|
// do nothing
|
|
|
|
})
|
|
|
|
.count();
|
|
|
|
|
|
|
|
// external function
|
|
|
|
let _ = (0..3).map(do_something).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_something<T>(t: T) -> String {
|
|
|
|
unimplemented!()
|
2019-08-15 20:56:27 +00:00
|
|
|
}
|