- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
Clippy +nightly 0.1.87 (17067e9ac6 2025-05-09) suggests that:
warning: this `if` statement can be collapsed --> src/obj.rs:92:9 | 92 | / if let Some(current_line) = self.lines.last_mut() { 93 | | if !current_line.is_empty() { 94 | | if let Some(&first_index) = current_line.first() { 95 | | current_line.push(first_index); ... | 98 | | } | |_________^
And when i apply that, like this:
if let Some(current_line) = self.lines.last_mut() && !current_line.is_empty() { if let Some(&first_index) = current_line.first() { current_line.push(first_index); } }
clippy +stable says:
error[E0658]: `let` expressions in this position are unstable --> src/obj.rs:92:12 | 92 | if let Some(current_line) = self.lines.last_mut() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
Lint Name
clippy::collapsible_if
Reproducer
I tried this code:
pub fn close_line(&mut self) { if let Some(current_line) = self.lines.last_mut() { if !current_line.is_empty() { if let Some(&first_index) = current_line.first() { current_line.push(first_index); } } } }
clippy +nightly suggested this:
pub fn close_line(&mut self) { if let Some(current_line) = self.lines.last_mut() && !current_line.is_empty() { if let Some(&first_index) = current_line.first() { current_line.push(first_index); } } }
I expected to see this happen:
Not to be hit with a "error[E0658]: let
expressions in this position are unstable" in +stable
Version
rustc 1.87.0 (17067e9ac 2025-05-09) binary: rustc commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359 commit-date: 2025-05-09 host: aarch64-apple-darwin release: 1.87.0 LLVM version: 20.1.1
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have