Skip to content

Item used in (unused) item named _name is still deemed dead #142075

Description

@DoubleHyphen

Code

const _MY_CODE_IS_CORRECT: bool = true;

const fn sanity_check() {
    let true = _MY_CODE_IS_CORRECT else {
        panic!();
    };
}

const _SANITY_CHECK: () = sanity_check();

Current output

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

Desired output

Compiling with no warnings.

Rationale and extra context

I have created some modules. I want each of them to fail to compile if it is not correct. To that end, I instituted a sanity_check in the crate, which is called within each module as const _SANITY_CHECK: () = crate::sanity_check();

The problem is that, because the _SANITY_CHECK consts are obviously not used anywhere, the entire sanity_check function is considered unused too. As one can tell, it is in fact very much used, and serves a very important purpose.

I guess this could be worked around by renaming it to _sanity_check, but in this case leaving the function actually unused would return no warnings, which is less than ideal.

Other cases

Rust Version

I tried it in the play-ground. I tried to find the version there but failed—that said, it's always the most recent one, isn't it?

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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_codeL-false-positiveLint: False positive (should not have fired).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