snippetrustMajor
How to pass rustc flags to cargo?
Viewed 0 times
howflagsrustccargopass
Problem
I am trying to disable dead code warnings. I tried the following
➜ rla git:(master) ✗ cargo build -- -A dead_code
error: Invalid arguments.
So I am wondering how would I pass rustc arguments to cargo?
cargo build -- -A dead_code➜ rla git:(master) ✗ cargo build -- -A dead_code
error: Invalid arguments.
So I am wondering how would I pass rustc arguments to cargo?
Solution
You can pass flags through Cargo by several different means:
However, in your specific case of configuring lints, you don't need to use compiler flags; you can also enable and disable lints directly in the source code using attributes. This may in fact be a better option as it's more robust, more targeted, and doesn't require you to alter your build system setup:
See also:
cargo rustc, which only affects your crate and not its dependencies.
- The
RUSTFLAGSenvironment variable, which affects dependencies as well.
- Some flags have a proper Cargo option, e.g.,
-C ltoand-C panic=abortcan be specified in theCargo.tomlfile.
- Add flags in
.cargo/configusing one of therustflags=keys.
However, in your specific case of configuring lints, you don't need to use compiler flags; you can also enable and disable lints directly in the source code using attributes. This may in fact be a better option as it's more robust, more targeted, and doesn't require you to alter your build system setup:
#![deny(some_lint)] // deny lint in this module and its children
#[allow(another_lint)] // allow lint in this function
fn foo() {
...
}See also:
- How to disable unused code warnings in Rust?
Code Snippets
#![deny(some_lint)] // deny lint in this module and its children
#[allow(another_lint)] // allow lint in this function
fn foo() {
...
}Context
Stack Overflow Q#38040327, score: 81
Revisions (0)
No revisions yet.