Skip to content

Incorrect "function is never used" for function only used in a const assertion #130213

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

Closed
RalfJung opened this issue Sep 11, 2024 · 4 comments
Closed
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-dead_code Lint: dead_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Sep 11, 2024

Code

const fn black_box<T>(x: T) -> T { x }

const _: () = {
    assert!(black_box(5) == 5);
};

Current output

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

Desired output

(none)

Rationale and extra context

The function is used in a const assertion -- that can have a side-effect so it should be considered a "use".

Other cases

No response

Rust Version

Current nightly

Anything else?

No response

@RalfJung RalfJung added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 11, 2024
@fmease fmease added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-dead_code Lint: dead_code and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Sep 11, 2024
@CastilloDel
Copy link
Contributor

CastilloDel commented Sep 11, 2024

Hey! I would like to tackle this. Could you give some pointers on where to look? I'm still unfamiliar with the codebase. EDIT: I guess most of it will be in compiler/rustc_passes/src/dead.rs, but any extra pointer is appreciated!

@rustbot claim

@RalfJung
Copy link
Member Author

Sorry, I got no idea. Maybe try the t-compiler/help stream on Zulip.

@zachs18
Copy link
Contributor

zachs18 commented Sep 12, 2024

Related #118424

@RalfJung
Copy link
Member Author

Ah indeed, this is a duplicate.

@RalfJung RalfJung closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-dead_code Lint: dead_code 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

4 participants