Skip to content

diverging_sub_expression false negative on diverging body of block #10776

Closed
@dtolnay

Description

@dtolnay

Summary

diverging_sub_expression triggers on … || diverge() but not … || { diverge(); }. It should trigger equivalently on both.

This came up due to rust-lang/rust#104134 breaking this test in clippy:

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:36:30
|
LL | _ => true || panic!("boo"),
| ^^^^^^^^^^^^^

due to the panic! expansion changing from core::panicking::panic_fmt(…) to { core::panicking::panic_fmt(…); }.

Lint Name

diverging_sub_expression

Reproducer

True positive:

fn main() {
    let lhs = false;
    let _ = lhs || return;
}
$ cargo clippy

warning: sub-expression diverges
 --> src/main.rs:3:20
  |
3 |     let _ = lhs || return;
  |                    ^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
  = note: `#[warn(clippy::diverging_sub_expression)]` on by default

False negative:

fn main() {
    let lhs = false;
    let _ = lhs || { return; };
}
$ cargo clippy

... nothing

Version

rustc 1.71.0-nightly (2c41369ac 2023-05-13)
binary: rustc
commit-hash: 2c41369acc445d04129db40ba998dd7a89fb0d2e
commit-date: 2023-05-13
host: aarch64-apple-darwin
release: 1.71.0-nightly
LLVM version: 16.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions