{"id":1155,"hash":"a0bceafb6f2f22ff3c4c7580b9e02e559edbccfeb8bab98ab3e4b5f9f78a9a86","pattern":"How do you disable dead code warnings at the crate level in Rust?","full_message":"While tinkering in Rust, I repeatedly encountered a lot of dead code warnings that made it difficult to focus. I tried using the outer attribute #[allow(dead_code)], but it only silences one warning at a time.\n\nstruct SemanticDirection;\n\nfn main() {}\n\nwarning: struct `SemanticDirection` is never constructed\n --> src\\main.rs:1:8\n  |\n1 | struct SemanticDirection;\n  |        ^^^^^^^^^^^^^^^^^\n  |\n  = note: `#[warn(dead_code)]` on by default\n\nHow do I disable these warnings at the crate level?","ecosystem":"cargo","package_name":"compiler-warnings","package_version":null,"solution":"You can either:\n\nAdd an allow attribute on a struct, module, function, etc.:\n\n#[allow(dead_code)]\nstruct SemanticDirection;\n\nAdd an allow as a crate-level attribute; notice the !:\n\n#![allow(dead_code)]\n\nPass it to rustc:\n\nrustc -A dead_code main.rs\n\nPass it using cargo via the RUSTFLAGS environment variable:\n\nRUSTFLAGS=\"$RUSTFLAGS -A dead_code\" cargo build","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/25877285/how-do-you-disable-dead-code-warnings-at-the-crate-level-in-rust","votes":567,"created_at":"2026-04-19T04:52:27.228034+00:00","updated_at":"2026-04-19T04:52:27.228034+00:00"}