[英]How to pass rustc flags to cargo?
I am trying to disable dead code warnings.我正在尝试禁用死代码警告。 I tried the following
我尝试了以下
cargo build -- -A dead_code
➜ rla git:(master) ✗ cargo build -- -A dead_code error: Invalid arguments.
➜ rla git:(master) ✗ cargo build -- -A dead_code 错误:arguments 无效。
So I am wondering how would I pass rustc arguments to cargo?所以我想知道如何将 rustc arguments 传递给货物?
You can pass flags through Cargo by several different means: 您可以通过几种不同的方式通过Cargo传递旗帜:
cargo rustc
, which only affects your crate and not its dependencies. cargo rustc
,只影响你的箱子,而不是它的依赖。 RUSTFLAGS
environment variable, which affects dependencies as well. RUSTFLAGS
环境变量,它也会影响依赖关系。 -C lto
and -C panic=abort
can be specified in the Cargo.toml
file. -C lto
和-C panic=abort
可以在Cargo.toml
文件中指定。 .cargo/config
using one of the rustflags=
keys. rustflags=
键在.cargo/config
添加标志。 However, in your specific case of configuring lints, you don't need to use compiler flags; 但是,在配置lints的特定情况下,您不需要使用编译器标志; you can also enable and disable lints directly in the source code using attributes.
您还可以使用属性直接在源代码中启用和禁用lints。 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: 也可以看看:
You can disable dead code warnings by modifying config.toml file.您可以通过修改 config.toml 文件来禁用死代码警告。 if file doesn't exists create one as below locations.
如果文件不存在,请在以下位置创建一个。
Windows: %USERPROFILE%\.cargo\config.toml
Unix: $HOME/.cargo/config.toml
Then add below line然后添加下面一行
[target.'cfg(target_family = "windows")']
rustflags = ["-Adead_code"]
If you dont want to see any unused variable warnings add below line如果您不想看到任何未使用的变量警告,请在下面添加
[target.'cfg(target_family = "windows")']
rustflags = ["-Aunused"]
Don't forget to disable these before Production:)不要忘记在生产前禁用它们:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.