Skip to content
New issue

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

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

Already on GitHub? # to your account

manual_ok_err automatic fix doesn't add {} when after else #14239

Closed
Sliman4 opened this issue Feb 17, 2025 · 1 comment · Fixed by #14240
Closed

manual_ok_err automatic fix doesn't add {} when after else #14239

Sliman4 opened this issue Feb 17, 2025 · 1 comment · Fixed by #14240
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Sliman4
Copy link

Sliman4 commented Feb 17, 2025

Summary

Broken code after applying automatic fix

Reproducer

I tried this code:

fn main() {
    let n = if false {
        None
    } else if let Ok(n) = "1".parse::<u8>() {
        Some(n)
    } else {
        None
    };
}

with --fix

I expected to see this happen:

fn main() {
    let n = if false {
        None
    } else {
        "1".parse::<u8>().ok()
    };
}

Instead, this happened:

fn main() {
    let n = if false {
        None
    } else "1".parse::<u8>().ok();
}

Version

rustc 1.86.0-nightly (9cd60bd2c 2025-02-15)
binary: rustc
commit-hash: 9cd60bd2ccc41bc898d2ad86728f14035d2df72d
commit-date: 2025-02-15
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

@Sliman4 Sliman4 added the C-bug Category: Clippy is not doing the correct thing label Feb 17, 2025
@samueltardieu
Copy link
Contributor

@Sliman4 Thanks for your report.

@samueltardieu samueltardieu added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Feb 17, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 17, 2025
If the part being replaced is an `if` expression following an `else`,
the replacement expression must be blockified.

Fix #14239

changelog: [`manual_ok_err`]: fix replacement expression if it follows
an `else`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants