-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Function used in anonymous constant is not considered used #104084
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
So unlike Giving the constant a name and using the constant suppresses the warning: fn foo() {}
const fn bar() {}
fn main() {
let _ = foo();
const A: () = bar();
let _ = A;
} Do you have a more detailed explanation if you hit this in production and was confused by the warning? |
Sure: I'm using it in a test that runs at compile time. The code doesn't need to actually produce anything (in other words, there's no const value that's used by another part of the program), it just needs to compile successfully. The code is here if you're curious. We also (in our zerocopy-derive crate) emit code of the form |
FWIW, you can suppress the warning by putting const fn bar() {}
fn main() {
#[allow(dead_code)]
const _: () = bar();
} |
Closing this as it is intended behaviour for dead code |
I have the following code:
Even though both
foo
andbar
are used, I get an unused warning forbar
:Version
Rust 1.65.0
The text was updated successfully, but these errors were encountered: