-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
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 haveI-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
The lint triggers even when both sides of the conditional use the same variable and consume it.
Lint Name
option_if_let_else
Reproducer
I tried this code:
if let Ok(data) = str::from_utf8(&loaded) {
ExportData::Human(data.into())
} else {
ExportData::Bytes(loaded.into_inner())
}I saw this happen:
str::from_utf8(&loaded).map_or_else(|_| ExportData::Bytes(loaded.into_inner()), |data| ExportData::Human(data.into()))
// Doesn't compile: cannot move out of `loaded` because it is borrowed [E0505] move out of `loaded` occurs hereVersion
rustc 1.79.0-nightly (3a36386dc 2024-04-25)
binary: rustc
commit-hash: 3a36386dc1075018dc7ca2640a2656adb31a61fe
commit-date: 2024-04-25
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4
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 haveI-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