I noticed that in order for a piece of code to not be classified as dead, it has to be reachable from all binaries. Example:
Cargo.toml:
[[bin]]
name = "main_one"
path = "src/main_one.rs"
[[bin]]
name = "main_two"
path = "src/main_two.rs"
main_one.rs:
mod utils;
fn main() {
print!("Hello, ");
utils::function_in_question();
}
main_two.rs:
mod utils;
fn main() {
print!("Hello, ");
// utils::function_in_question();
}
utils.rs:
pub fn function_in_question() {
println!("world!");
}
This reports function_in_question
as dead code, even though it's reachable from main_one.rs
. Uncommenting it fixes this issue. Works also if it's present only in main_two.rs
.
Although there is some rationale behind this behavior, it is annyoing to have VSCode complain about this all the time + the output of Clippy is spammed by these warnings. Is there a solution to at least surpress dead code detection globally? Restructuring the whole project with cargo workspaces should be avoided.