rust/tests/ui/suspicious_map.stderr
Robert Spencer acc3842d43 Add new map_with_unused_argument_over_ranges lint
This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```
or
```rust
  let something : Vec<_> =
      std::iter::repeat_n(1 + 2 + 3, 100)
      .collect();
```

That is, a map over a range which does nothing with the parameter
passed to it is simply a function (or closure) being called `n`
times and could be more semantically expressed using `take`.
2024-10-29 21:32:00 +00:00

21 lines
774 B
Plaintext

error: this call to `map()` won't have an effect on the call to `count()`
--> tests/ui/suspicious_map.rs:5:13
|
LL | let _ = (0..3).map(|x| x + 2).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
= note: `-D clippy::suspicious-map` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]`
error: this call to `map()` won't have an effect on the call to `count()`
--> tests/ui/suspicious_map.rs:9:13
|
LL | let _ = (0..3).map(f).count();
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
error: aborting due to 2 previous errors