Skip to content

Iterate over slices in three loops so Clippy passes on Rust 1.100 - #23

Merged
schreck61 merged 1 commit into
mainfrom
clippy-rust-1.100
Nov 15, 2026
Merged

schreck61 merged 1 commit into
mainfrom
clippy-rust-1.100

Conversation

@schreck61

Copy link
Copy Markdown
Owner

What

Three loops iterate over a slice instead of indexing it with the loop variable of a range:

  • RlController::shield and RlController::features (src/control/rl.rs) go through the sensor view's movements with ctx.view.moves.iter().enumerate().take(net.movements.len()).
  • Sim::leader (src/sim/mod.rs) goes through the rest of the vehicle's route with &v.route[v.ri + 1..].

Behavior doesn't change. Each loop visits the same elements in the same order: SensorView::new gives the view one entry per movement, and leader has already read route[ri], so the rest of the route is a valid slice.

Why

The required Clippy check fails on every pull request, whatever the pull request changes. CI installs the newest stable Rust on every run, and since it moved to Rust 1.100.0, Clippy reports needless_range_loop for these three loops on main. #22, which changes no Rust code, failed that way on 2026-11-12. Nothing can merge until main is clean.

Testing

Rust 1.100 isn't installed on the machine this was written on, so the Clippy check on this pull request is the first run of the change on that release. Before opening it:

  • cargo fmt --all --check is clean.
  • cargo clippy --locked --release --all-targets -- -D warnings, and the same for --target wasm32-unknown-unknown --bin intersection-lab, are clean on Rust 1.99.0.
  • Clippy from the 2026-10-10 nightly reports the same three errors as CI does on main, and none with this change.
  • cargo test --locked --release passes: the same 74 tests as on main, none changed.
  • bench all 20 6 prints the same numbers before and after, apart from the run times.
  • A scratch program, not part of this pull request, hashed every vehicle's position, speed and acceleration after every step, and the outputs of features and shield at signals. The hashes are the same before and after, over 96 runs: every layout and controller with three seeds, 15 simulated minutes each.

CI installs the newest stable Rust on every run. Since it moved to
Rust 1.100.0, the required Clippy check fails on every pull request,
whatever the pull request changes: Clippy now reports
needless_range_loop on main for three loops that index a slice with
the loop variable of a range. Two go through the movements, in
RlController::shield and RlController::features, and one goes through
the rest of a vehicle's route, in Sim::leader.

The loops now iterate over the slices instead. Behavior does not
change, because each loop visits the same elements in the same order:
SensorView::new gives the view one entry per movement, and leader has
already read route[ri], so the rest of the route is a valid slice.

Signed-off-by: Jim Schreckengast <schreck@gmail.com>
@schreck61
schreck61 enabled auto-merge (rebase) November 15, 2026 05:54
@schreck61
schreck61 merged commit 639d22a into main Nov 15, 2026
13 checks passed
@schreck61
schreck61 deleted the clippy-rust-1.100 branch November 15, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant