Skip to content

[if_then_some_else_none] extra ; and } inside Some()? #15055

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

Closed
madonuko opened this issue Jun 14, 2025 · 1 comment
Closed

[if_then_some_else_none] extra ; and } inside Some()? #15055

madonuko opened this issue Jun 14, 2025 · 1 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

Comments

@madonuko
Copy link

Summary

reproed on my machine and also on playground

Lint Name

if_then_some_else_none

Reproducer

#[warn(clippy::if_then_some_else_none)]
fn f(bytes: Vec<u8>) -> Option<[u8; 32]> {
    if bytes.len() == 32 {
        let mut array = [0u8; 32];
        array.copy_from_slice(&bytes);
        Some(array)
    } else {
        None
    }
}
    Checking playground v0.0.1 (/playground)
warning: function `f` is never used
 --> src/lib.rs:2:4
  |
2 | fn f(bytes: Vec<u8>) -> Option<[u8; 32]> {
  |    ^
  |
  = note: `#[warn(dead_code)]` on by default

warning: this could be simplified with `bool::then`
 --> src/lib.rs:3:5
  |
3 | /     if bytes.len() == 32 {
4 | |         let mut array = [0u8; 32];
5 | |         array.copy_from_slice(&bytes);
6 | |         Some(array)
7 | |     } else {
8 | |         None
9 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
note: the lint level is defined here
 --> src/lib.rs:1:8
  |
1 | #[warn(clippy::if_then_some_else_none)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try
  |
3 ~     (bytes.len() == 32).then(||  { let mut array = [0u8; 32];
4 +         array.copy_from_slice(&bytes);
5 +         Some(; array })
  |

warning: `playground` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p playground` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.36s

Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Additional Labels

No response

@madonuko madonuko 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 Jun 14, 2025
@samueltardieu
Copy link
Contributor

This is a duplicate of #15005 and will be fixed by #15014.

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
Projects
None yet
Development

No branches or pull requests

2 participants