When I compile my code with cargo, I get warnings from code in dependencies. This is not my code and I will not be fixing it. These warnings are noise which could hide problems in my own code.
How do I disable all of these warnings, in included crates and their dependencies, but not disable warnings in my own code?
The following does not work:
#[allow(warnings)]
extern crate foo;
Perhaps it works on foo itself, but not on its dependencies.
A minimal example follows:
$ find rust-test/
rust-test/
rust-test/b
rust-test/b/Cargo.toml
rust-test/b/src
rust-test/b/src/lib.rs
rust-test/mine
rust-test/mine/Cargo.toml
rust-test/mine/src
rust-test/mine/src/main.rs
rust-test/a
rust-test/a/Cargo.toml
rust-test/a/src
rust-test/a/src/lib.rs
"mine" is the code I am working on. a and b are libraries that generate warnings.
$ cat Cargo.toml 
[package]
name = "mine"
[dependencies]
a = {path = "../a"}
$ cat a/Cargo.toml 
[package]
name = "a"
[dependencies]
b = {path = "../b"}
$ cat b/Cargo.toml 
[package]
name = "b"
In rust-test/mine:
$ cargo b
warning: no edition set: defaulting to the 2015 edition while the latest is 2024
warning: function `test_b` is never used
 --> /home/anon/rust-test/b/src/lib.rs:1:4
  |
1 | fn test_b() -> () {}
  |    ^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
warning: `b` (lib) generated 1 warning
warning: function `test_a` is never used
 --> /home/anon/rust-test/a/src/lib.rs:1:4
  |
1 | fn test_a() -> () {}
  |    ^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
warning: `a` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
The source files contain only the unused functions warned about.
When I compile my code with cargo, I get warnings from code in dependencies. This is not my code and I will not be fixing it. These warnings are noise which could hide problems in my own code.
Cargo already has a rule to automatically hide such warnings for precisely these reasons.
The problem in your case is that the rule is to hide warnings if the dependency is from a remote source — git, crates.io, or other registry. When the dependency is specified by path, Cargo assumes that it is code you are maintaining.
Therefore, possible solutions are:
path dependency on, adding #[allow(warnings)].git or crates.io dependency instead of path.cargo vendor.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With