如何在 Rust 中禁用未使用的代码警告? [英] How to disable unused code warnings in Rust?
本文介绍了如何在 Rust 中禁用未使用的代码警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct SemanticDirection;
fn main() {}
warning: struct is never used: `SemanticDirection`
--> src/main.rs:1:1
|
1 | struct SemanticDirection;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
对于任何严重的事情,我都会重新打开这些警告,但我只是在修改语言,这让我很生气.
I will turn these warnings back on for anything serious, but I am just tinkering with the language and this is driving me bats.
我尝试将 #[allow(dead_code)]
添加到我的代码中,但是没有用.
I tried adding #[allow(dead_code)]
to my code, but that did not work.
推荐答案
您可以:
在结构、模块、函数等上添加
allow
属性:
#[allow(dead_code)]
struct SemanticDirection;
添加板条箱级allow
属性;注意 !
:
#![allow(dead_code)]
传递给rustc
:
rustc -A dead_code main.rs
使用 cargo
通过 RUSTFLAGS
环境变量传递它:
Pass it using cargo
via the RUSTFLAGS
environment variable:
RUSTFLAGS="$RUSTFLAGS -A dead_code" cargo build
这篇关于如何在 Rust 中禁用未使用的代码警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文