-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 have
Description
Summary
The lint triggers even though bool::then doesn't work with async code.
Lint Name
if_then_some_else_none
Reproducer
I tried this code:
pub async fn foo() -> u32 {
todo!()
}
pub async fn bar(cond: bool) -> Option<u32> {
if cond { Some(foo().await) } else { None }
}I saw this happen:
The following errors were reported:
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> main/lib/src/chargesession.rs:365:24
|
365 | cond.then(|| foo().await)
| -- ^^^^^ only allowed inside `async` functions and blocks
| |
| this is not `async`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0728`.
Original diagnostics will follow.
warning: this could be simplified with `bool::then`
--> main/lib/src/chargesession.rs:365:5
|
365 | if cond { Some(foo().await) } else { None }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cond.then(|| foo().await)`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#if_then_some_else_none
= note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]`
I expected to see this happen:
Lint should not trigger on this code.
Version
rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.91.1
LLVM version: 21.1.2
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 have