-
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-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-nurseryLint: Currently in the nursery groupLint: Currently in the nursery group
Description
Summary
equatable_if_let
tries to replace a pattern into a ==
, but the two differ slightly in their semantics when it comes to reference. Hence the current implementation creates a suggestion that causes a type mismatch error when adopted.
Reproducer
I tried this code:
#![warn(clippy::pedantic, clippy::nursery)]
fn bar() {todo!()}
fn baz() {todo!()}
pub fn foo(cs: &[char]) {
let mut iter = cs.iter();
if let Some('i') = iter.next() {
bar();
} else {
baz();
}
}
I expected to see this happen: Clippy suggests
try: `iter.next() == Some(&'i')`
Instead, this happened: Clippy suggested
try: `iter.next() == Some('i')`
which is a wrong suggestion because replacing the original code with this snippet causes a type error.
Version
rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-pc-windows-msvc
release: 1.60.0
LLVM version: 14.0.0
Additional Labels
@rustbot label +l-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-nurseryLint: Currently in the nursery groupLint: Currently in the nursery group