Skip to content

Function only used in const assert is treated as dead code #142104

Closed
@clarfonthey

Description

@clarfonthey

I tried this code: playground link

const fn is_nonzero(x: u8) -> bool {
    x != 0
}
const _: () = {
    assert!(is_nonzero(2));
};

I expected to compile without any warnings.

Instead, it indicates that is_nonzero is dead code:

warning: function `is_nonzero` is never used
 --> src/lib.rs:1:10
  |
1 | const fn is_nonzero(x: u8) -> bool {
  |          ^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (5d707b07e 2025-06-02)
binary: rustc
commit-hash: 5d707b07e42766c080c5012869c9988a18dcbb83
commit-date: 2025-06-02
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-dead_codeLint: dead_codeT-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