Repository: serde-rs/json (language: rust)

Issue:
Unused result warning in json! macro.
Stumbled upon a warning coming from the `json!` macro that will cause compiles to fail if the `unused_results` warning is set with [this test case](http://play.rust-lang.org/?gist=baf66a86706282966f5109f537b74041&version=stable&mode=debug&edition=2015). Here's what I get running it with `cargo +nightly rustc -- -Z external-macro-backtrace`:

```
/mnt/c/Users/David/Projects/repro-serde-unused-result master*
❯ cargo +nightly rustc -- -Z external-macro-backtrace
   Compiling unicode-xid v0.1.0
   Compiling serde v1.0.70
   Compiling dtoa v0.4.3
   Compiling itoa v0.4.2
   Compiling proc-macro2 v0.4.6
   Compiling quote v0.6.3
   Compiling syn v0.14.4
   Compiling serde_derive v1.0.70
   Compiling serde_json v1.0.22
   Compiling repro-serde-unused-result v0.1.0 (file:///mnt/c/Users/David/Projects/repro-serde-unused-result)
error: unused result=============================================>     ] 11/12: repro-serde-unused-result
    |
   ::: <json macros>:1:1
    |
1   |    ( $ ( $ json : tt ) + ) => { json_internal ! ( $ ( $ json ) + ) } ;
    |    -------------------------------------------------------------------
    |    |                            |
    |    |                            in this macro invocation
    |    in this expansion of `json!`
   --> <json_internal macros>:41:61
    |
1   |  / ( @ array [ $ ( $ elems : expr , ) * ] ) => { vec ! [ $ ( $ elems , ) * ] } ;
2   |  | ( @ array [ $ ( $ elems : expr ) , * ] ) => { vec ! [ $ ( $ elems ) , * ] } ;
3   |  | ( @ array [ $ ( $ elems : expr , ) * ] null $ ( $ rest : tt ) * ) => {
4   |  | json_internal ! (
...    |
41  |  | $ object . insert ( ( $ ( $ key ) + ) . into (  ) , $ value ) ; } ; (
    |  |                                                             ^^^
...    |
105 |  | @ object object (  ) ( $ ( $ tt ) + ) ( $ ( $ tt ) + ) ) ; object } ) } ; (
106 |  | $ other : expr ) => { $ crate :: to_value ( & $ other ) . unwrap (  ) } ;
    |  |_________________________________________________________________________- in this expansion of `json_internal!`
    |
   ::: src/main.rs:10:20
    |
10  |        println!("{}", json!({
    |  _____________________-
11  | |          "architecture": {
12  | |              "name": name,
13  | |              "ids": ids
14  | |          }
15  | |      }));
    | |_______- in this macro invocation
    |
note: lint level defined here
   --> src/main.rs:1:9
    |
1   | #![deny(unused_results)]
    |         ^^^^^^^^^^^^^^

error: unused result
    |
   ::: <json macros>:1:1
    |
1   |         ( $ ( $ json : tt ) + ) => { json_internal ! ( $ ( $ json ) + ) } ;
    |         -------------------------------------------------------------------
    |         |                            |
    |         |                            in this macro invocation (#2)
    |         in this expansion of `json!` (#1)
   --> <json_internal macros>:35:61
    |
1   |         ( @ array [ $ ( $ elems : expr , ) * ] ) => { vec ! [ $ ( $ elems , ) * ] } ;
    |        _-
    |       |_|
    |      ||_|
    |     |||_|
    |    ||||
2   |    |||| ( @ array [ $ ( $ elems : expr ) , * ] ) => { vec ! [ $ ( $ elems ) , * ] } ;
3   |    |||| ( @ array [ $ ( $ elems : expr , ) * ] null $ ( $ rest : tt ) * ) => {
4   |    |||| json_internal ! (
...      ||||
35  |    |||| $ object . insert ( ( $ ( $ key ) + ) . into (  ) , $ value ) ; json_internal
    |    ||||                                                             ^^^
...      ||||
65  |    |||| @ object $ object [ $ ( $ key ) + ] ( json_internal ! ( { $ ( $ map ) * } ) )
    |    ||||                                       ------------------------------------- in this macro invocation (#5)
...      ||||
93  | /  |||| json_internal ! (
94  | |  |||| @ object $ object ( $ ( $ key ) * $ tt ) ( $ ( $ rest ) * ) ( $ ( $ rest ) * )
95  | |  |||| ) ; } ; ( null ) => { $ crate :: Value :: Null } ; ( true ) => {
    | |__||||___- in this macro invocation (#4)
...      ||||
104 |    |||| let mut object = $ crate :: Map :: new (  ) ; json_internal ! (
    |  __||||_______________________________________________-
105 | |  |||| @ object object (  ) ( $ ( $ tt ) + ) ( $ ( $ tt ) + ) ) ; object } ) } ; (
    | |__||||__________________________________________________________- in this macro invocation (#3)
106 |    |||| $ other : expr ) => { $ crate :: to_value ( & $ other ) . unwrap (  ) } ;
    |    ||||                                                                         -
    |    ||||_________________________________________________________________________|
    |    |||__________________________________________________________________________in this expansion of `json_internal!` (#2)
    |    ||___________________________________________________________________________in this expansion of `json_internal!` (#3)
    |    |____________________________________________________________________________in this expansion of `json_internal!` (#4)
    |                                                                                 in this expansion of `json_internal!` (#5)
    |
   ::: src/main.rs:10:20
    |
10  |             println!("{}", json!({
    |  __________________________-
11  | |               "architecture": {
12  | |                   "name": name,
13  | |                   "ids": ids
14  | |               }
15  | |           }));
    | |____________- in this macro invocation (#1)

error: unused result
    |
   ::: <json macros>:1:1
    |
1   |         ( $ ( $ json : tt ) + ) => { json_internal ! ( $ ( $ json ) + ) } ;
    |         -------------------------------------------------------------------
    |         |                            |
    |         |                            in this macro invocation (#2)
    |         in this expansion of `json!` (#1)
   --> <json_internal macros>:41:61
    |
1   |         ( @ array [ $ ( $ elems : expr , ) * ] ) => { vec ! [ $ ( $ elems , ) * ] } ;
    |        _-
    |       |_|
    |      ||_|
    |     |||_|
    |    ||||
2   |    |||| ( @ array [ $ ( $ elems : expr ) , * ] ) => { vec ! [ $ ( $ elems ) , * ] } ;
3   |    |||| ( @ array [ $ ( $ elems : expr , ) * ] null $ ( $ rest : tt ) * ) => {
4   |    |||| json_internal ! (
...      ||||
41  |    |||| $ object . insert ( ( $ ( $ key ) + ) . into (  ) , $ value ) ; } ; (
    |    ||||                                                             ^^^
...      ||||
65  |    |||| @ object $ object [ $ ( $ key ) + ] ( json_internal ! ( { $ ( $ map ) * } ) )
    |    ||||                                       ------------------------------------- in this macro invocation (#5)
...      ||||
93  | /  |||| json_internal ! (
94  | |  |||| @ object $ object ( $ ( $ key ) * $ tt ) ( $ ( $ rest ) * ) ( $ ( $ rest ) * )
95  | |  |||| ) ; } ; ( null ) => { $ crate :: Value :: Null } ; ( true ) => {
    | |__||||___- in this macro invocation (#4)
...      ||||
104 |    |||| let mut object = $ crate :: Map :: new (  ) ; json_internal ! (
    |  __||||_______________________________________________-
105 | |  |||| @ object object (  ) ( $ ( $ tt ) + ) ( $ ( $ tt ) + ) ) ; object } ) } ; (
    | |__||||__________________________________________________________- in this macro invocation (#3)
106 |    |||| $ other : expr ) => { $ crate :: to_value ( & $ other ) . unwrap (  ) } ;
    |    ||||                                                                         -
    |    ||||_________________________________________________________________________|
    |    |||__________________________________________________________________________in this expansion of `json_internal!` (#2)
    |    ||___________________________________________________________________________in this expansion of `json_internal!` (#3)
    |    |____________________________________________________________________________in this expansion of `json_internal!` (#4)
    |                                                                                 in this expansion of `json_internal!` (#5)
    |
   ::: src/main.rs:10:20
    |
10  |             println!("{}", json!({
    |  __________________________-
11  | |               "architecture": {
12  | |                   "name": name,
13  | |                   "ids": ids
14  | |               }
15  | |           }));
    | |____________- in this macro invocation (#1)

error: aborting due to 3 previous errors

error: Could not compile `repro-serde-unused-result`.

To learn more, run the command again with --verbose.
```


Discussion / hints:

Fix patch:
diff --git a/src/macros.rs b/src/macros.rs
index 29e16b7ab..a3accf75b 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`.


Test patch:
diff --git a/tests/test.rs b/tests/test.rs
index 4e9c0ccd9..08d038837 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1847,6 +1847,9 @@ fn test_json_macro() {
         (<Result<&str, ()> as Clone>::clone(&Ok("")).unwrap()): "ok",
         (<Result<(), &str> as Clone>::clone(&Err("")).unwrap_err()): "err"
     });
+
+    #[deny(unused_results)]
+    let _ = json!({ "architecture": [true, null] });
 }
 
 #[test]