Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option_if_let_else results in code that doesn't compile #12723

Open
SUPERCILEX opened this issue Apr 27, 2024 · 0 comments
Open

option_if_let_else results in code that doesn't compile #12723

SUPERCILEX opened this issue Apr 27, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@SUPERCILEX
Copy link

SUPERCILEX commented Apr 27, 2024

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 here

Version

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

@SUPERCILEX SUPERCILEX added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 27, 2024
@Alexendoo Alexendoo added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants