可以声明会在Rust中警告未使用结果的函数吗? [英] Possible to declare functions that will warn on unused results in Rust?
本文介绍了可以声明会在Rust中警告未使用结果的函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Rust是否有一种方法来声明一个函数,对于任何类型,如果不使用它的结果都会发出警告?
Does Rust have a way to declare a function, where not using its result will warn - for any types?
类似于GCC的 __ attribute __((warn_unused_result));
吗?
推荐答案
从1.27开始,#[must_use]
也适用于函数.
As of 1.27, #[must_use]
works for functions too.
看来,#[must_use]
属性仅适用于 struct
s, enum
s和 union
s( union
在稳定的Rust中尚不可用):
It appears that the #[must_use]
attribute is only applicable to struct
s, enum
s and union
s (union
is not available in stable Rust yet, though): source. I think this means you can't override it for a function.
这篇关于可以声明会在Rust中警告未使用结果的函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文