Repository navigation
Iterate over slices in three loops so Clippy passes on Rust 1.100 - #23
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three loops iterate over a slice instead of indexing it with the loop variable of a range:
RlController::shieldandRlController::features(src/control/rl.rs) go through the sensor view's movements withctx.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::newgives the view one entry per movement, andleaderhas already readroute[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_loopfor these three loops onmain. #22, which changes no Rust code, failed that way on 2026-11-12. Nothing can merge untilmainis 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 --checkis 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.main, and none with this change.cargo test --locked --releasepasses: the same 74 tests as onmain, none changed.bench all 20 6prints the same numbers before and after, apart from the run times.featuresandshieldat signals. The hashes are the same before and after, over 96 runs: every layout and controller with three seeds, 15 simulated minutes each.