From 5c931e0536699cb9383ce3b4943bea68fc22ecf9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 16 Jul 2018 09:35:32 -0700 Subject: [PATCH] Make json macro compatible with deny(unused_results) The unused_results lint triggers on any function call returning anything other than () or ! that is not used. The Map::insert function returns Option of the previous value of the inserted key. --- src/macros.rs | 4 ++-- tests/test.rs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 29e16b7..a3accf7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -161,7 +161,7 @@ macro_rules! json_internal { // Insert the current entry followed by trailing comma. (@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { - $object.insert(($($key)+).into(), $value); + let _ = $object.insert(($($key)+).into(), $value); json_internal!(@object $object () ($($rest)*) ($($rest)*)); }; @@ -172,7 +172,7 @@ macro_rules! json_internal { // Insert the last entry without trailing comma. (@object $object:ident [$($key:tt)+] ($value:expr)) => { - $object.insert(($($key)+).into(), $value); + let _ = $object.insert(($($key)+).into(), $value); }; // Next value is `null`. diff --git a/tests/test.rs b/tests/test.rs index 4e9c0cc..08d0388 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1847,6 +1847,9 @@ fn test_json_macro() { ( as Clone>::clone(&Ok("")).unwrap()): "ok", ( as Clone>::clone(&Err("")).unwrap_err()): "err" }); + + #[deny(unused_results)] + let _ = json!({ "architecture": [true, null] }); } #[test]