How to quiet a warning for a single statement in Rust?

后端 未结 2 504
甜味超标
甜味超标 2020-12-11 14:30

Say there is a single warning such as path_statements, unused_variables. Is there a way to ignore a single instant of this, without isolating them

2条回答
  •  萌比男神i
    2020-12-11 15:22

    If you want to silence all warnings of a kind in a module, write e.g. #![allow(dead_code)] (note the exclamation mark) at the top of the module. This will disable all warnings of this kind in the whole module. You can also call rustc with e.g. -A dead_code.

    You can disable all warnings by writing #![allow(warnings)] at the top of the module.

    You can insert a module (as described in the Rust book) where the specific warnings are ignored.

    As Lukas said, you can also write e.g. #[allow(dead_code)] on a statement or an expression.

提交回复
热议问题