From 877a944e86c38719c69d447dff797d09c2a045cd Mon Sep 17 00:00:00 2001 From: kraktus Date: Wed, 4 May 2022 14:42:28 +0200 Subject: [PATCH] Set type when purposely discarding result Raised by https://github.com/rust-lang/rust-clippy/issues/6841, as it is safer in case of refactoring --- src/attributes/diagnostics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attributes/diagnostics.md b/src/attributes/diagnostics.md index dd07fdb84..3326d1ec1 100644 --- a/src/attributes/diagnostics.md +++ b/src/attributes/diagnostics.md @@ -291,14 +291,14 @@ When used on a function in a trait implementation, the attribute does nothing. > ``` > Note: It is idiomatic to use a [let statement] with a pattern of `_` -> when a must-used value is purposely discarded. +> when a must-used value is purposely discarded. It is good practice to explicitely set the expected return type, so that in case of refactoring you need to validate discarding the new return type. > > ```rust > #[must_use] > fn five() -> i32 { 5i32 } > > // Does not violate the unused_must_use lint. -> let _ = five(); +> let _: i32 = five(); > ``` [Clippy]: https://github.com/rust-lang/rust-clippy