如何在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
使用货物
通过 RUSTFLAGS $ c $传递c>环境变量:
RUSTFLAGS="$RUSTFLAGS -A dead_code" cargo build
这篇关于如何在Rust中禁用未使用的代码警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文