-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Visit const
node in dead-code analysis
#118713
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
Visit const
node in dead-code analysis
#118713
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
I think this is intentional. If anything, we need to check if the item name of the const starts with |
Also, for the record, this also occurs in other items: fn foo() {}
//~^ WARN function `foo` is never used
fn _a() {
foo();
} I believe this should be fixed more consistently, then we can T-lang nominate this for their feedback. |
@rustbot author |
In variables, there is no warning about fn main() {
let x = 10;
let _y = x;
}
// There are no warnings. I may be mistaken, but I think the constants should be analyzed in the same way. const X: i32 = 10;
const _Y: i32 = X;
fn main() {}
/*
warning: constant `X` is never used
--> test.rs:20:7
|
20 | const X: i32 = 10;
| ^
|
= note: `#[warn(dead_code)]` on by default
*/ |
Furthremore, in the following code, the type alias type T = u32;
const _A: () = assert!(std::mem::size_of::<T>() != std::mem::size_of::<T>());
fn main() {}
/*
warning: type alias `T` is never used
--> test.rs:1:6
|
1 | type T = u32;
| ^
|
= note: `#[warn(dead_code)]` on by default
error[E0080]: evaluation of constant value failed
--> test.rs:2:16
|
2 | const _A: () = assert!(std::mem::size_of::<T>() != std::mem::size_of::<T>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::<T>() != std::mem::size_of::<T>()', test.rs:2:16
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
*/ |
@long-long-float FYI: when a PR is ready for review, send a message containing |
@JohnCSimon |
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this. @rustbot label: +S-inactive |
close #118424
I fixed to visit
const
node in dead-code analysis.Before this PR, the body of
const
node is not visited in dead-code analysis.Therefore the type
T
is detected as adead_code
.