如何将 rustc 标志传递给货物? [英] How to pass rustc flags to cargo?
问题描述
我正在尝试禁用死代码警告.我尝试了以下
cargo build -- A dead_code
<块引用>
➜ rla git:(master) ✗ cargo build --A dead_code错误:无效参数.
所以我想知道如何将 rustc 参数传递给货物?
你可以通过几种不同的方式通过 Cargo 传递标志:
cargo rustc
,它只影响你的 crate 而不是它的依赖项.RUSTFLAGS
环境变量,这也会影响依赖项.- 有些标志有适当的 Cargo 选项,例如
-C lto
和-C panic=abort
可以在Cargo.toml
中指定> 文件. - 在
.cargo/config
中添加标志a> 使用rustflags=
键之一.
但是,在您配置 lint 的特定情况下,您不需要使用编译器标志;您还可以使用属性直接在源代码中启用和禁用 lint.这实际上可能是一个更好的选择,因为它更强大、更有针对性,并且不需要您更改构建系统设置:
#![deny(some_lint)]//拒绝此模块及其子模块中的 lint#[allow(another_lint)]//在这个函数中允许 lintfn foo() {...}
另见:
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.
So I am wondering how would I pass rustc arguments to cargo?
You can pass flags through Cargo by several different means:
cargo rustc
, which only affects your crate and not its dependencies.- The
RUSTFLAGS
environment variable, which affects dependencies as well. - Some flags have a proper Cargo option, e.g.,
-C lto
and-C panic=abort
can be specified in theCargo.toml
file. - Add flags in
.cargo/config
using 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:
这篇关于如何将 rustc 标志传递给货物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!