Open
Description
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