How do you disable dead code warnings at the crate level in Rust?

You can either:

  • Add an allow attribute on a struct, module, function, etc.:

    struct SemanticDirection;
  • Add an allow as a crate-level attribute; notice the !:

  • Pass it to rustc:

    rustc -A dead_code
  • Pass it using cargo via the RUSTFLAGS environment variable:

    RUSTFLAGS="$RUSTFLAGS -A dead_code" cargo build

Leave a Comment