Skip to content

unconditional_panic lint getting recognized in code that actually panics condtionally #90534

Open
@pro465

Description

@pro465

I tried this code:

fn main() {
    let v: [i32; 0] = [];
    let _ = v.len() > 0 && v[0] == 0;
}

I expected to see this happen: code compiles and runs fine, without any error or panic

Instead, this happened:

error: this operation will panic at runtime
 --> t.rs:3:28
  |
3 |     let _ = v.len() > 0 && v[0] == 0;
  |                            ^^^^ index out of bounds: the length is 0 but the index is 0
  |
  = note: `#[deny(unconditional_panic)]` on by default

Meta

rustc --version --verbose:

rustc 1.56.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: armv7-linux-androideabi
release: 1.56.0
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-propArea: Constant propagationA-control-flowArea: Control flowA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions