Navigation Menu

Skip to content
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

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

Open
pro465 opened this issue Nov 3, 2021 · 7 comments
Labels
A-const-prop Area: Constant Propagation A-control-flow Area: Relating to control flow A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pro465
Copy link
Contributor

pro465 commented Nov 3, 2021

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
@pro465 pro465 added the C-bug Category: This is a bug. label Nov 3, 2021
@JanBeh
Copy link
Contributor

JanBeh commented Jun 24, 2022

Also note that this triggers the lint:

fn main() {
    let xs: [i32; 5] = [1, 2, 3, 4, 5];
    if false {
        println!("{}", xs[7]);
    }
}

(using rustc 1.63.0-nightly (43347397f 2022-06-23))

Example taken from URLO.

@JanBeh
Copy link
Contributor

JanBeh commented Jun 24, 2022

See also: #78803

@pro465
Copy link
Contributor Author

pro465 commented Jun 24, 2022

@JanBeh thanks for the update! hopefully somebody will notice that issue and prepare a fix

@Nilstrieb
Copy link
Member

Closing in favor of #78803

@Nilstrieb Nilstrieb closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
@pro465
Copy link
Contributor Author

pro465 commented Aug 18, 2023

@Nilstrieb , considering that this issue is still there in the latest nightly, even after #78803 was fixed, should we reopen this?

@Nilstrieb Nilstrieb reopened this Aug 21, 2023
@fmease
Copy link
Member

fmease commented Aug 21, 2023

@rustbot label T-compiler A-lint A-control-flow A-const-prop

@rustbot rustbot added A-const-prop Area: Constant Propagation A-control-flow Area: Relating to control flow A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2023
@ahqsoftwares
Copy link

There's something to note as well, it should be converted to a warning cuz the conditional part would never get called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-prop Area: Constant Propagation A-control-flow Area: Relating to control flow A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants