-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Item used in (unused) item named _name
is still deemed dead
#142075
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
Comments
I would expect |
_ NAME
is incorrectly deemed dead
_ NAME
is incorrectly deemed dead_NAME
is incorrectly deemed dead
To recap this reduces to const fn f() {} //~ WARN function `f` is never used
const _X: () = f(); However, we apparently don't do this for any other cases either (namely, propagating liveness via fn f() {} //~ WARN function `f` is never used
fn _g() { f() } |
_NAME
is incorrectly deemed dead_name
is still deemed dead
Also CC #118424 |
I think it’s a consistent, defensible choice to treat an underscore prefix as only suppressing the dead code lint for that one item, without counting as a “root” for the purpose of computing which things are reachable from exports/entry points. It could be done differently but there’s arguments for it as well. However, |
…it does when it's inside a module, though! const fn foo() {} // warning: function `foo` is never used
mod whatever {
pub const _: () = crate::foo();
} |
Code
Current output
Desired output
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 asconst _SANITY_CHECK: () = crate::sanity_check();
The problem is that, because the
_SANITY_CHECK
consts are obviously not used anywhere, the entiresanity_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
Anything else?
No response
The text was updated successfully, but these errors were encountered: