-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
Clippy suggests changing .last() to .next_back() which changes semantics when iterator pipeline is impure.
Reproducer
Consider this (a bit contrived) code:
let mut squares = vec![];
let last_square = [1, 2, 3]
.into_iter()
.map(|x| {
squares.push(x * x);
Some(x * x)
})
.last();
dbg!(squares, last_square);Clippy suggests changing .last() to .next_back() which dramatically changes the behaviour.
Version
rustc 1.87.0-nightly (3ea711f17 2025-03-09)
binary: rustc
commit-hash: 3ea711f17e3946ac3f4df11691584e2c56b4b0cf
commit-date: 2025-03-09
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Additional Labels
@rustbot label +I-suggestion-causes-bug
kadiwa4
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way