RS.CLIPPY.MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES

Map of a trivial closure (not dependent on parameter) over a range

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: map_with_unused_argument_over_ranges. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for Iterator::map over ranges without using the parameter which could be more clearly expressed using std::iter::repeat(...).take(...) or std::iter::repeat_n.

Why is this bad?

It expresses the intent more clearly to take the correct number of times from a generating function than to apply a closure to each number in a range only to discard them.

Example

let random_numbers : Vec<_> = (0..10).map(|_| { 3 + 1 }).collect();

Use instead:

let f : Vec<_> = std::iter::repeat( 3 + 1 ).take(10).collect();

Known Issues

This lint may suggest replacing a Map<Range> with a Take<RepeatWith>. The former implements some traits that the latter does not, such as DoubleEndedIterator.

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)