mirror of
https://github.com/serde-rs/json.git
synced 2025-10-04 16:25:42 +00:00
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<Value> of the previous value of the inserted key.
This commit is contained in:
parent
1b36cec484
commit
5c931e0536
@ -161,7 +161,7 @@ macro_rules! json_internal {
|
|||||||
|
|
||||||
// Insert the current entry followed by trailing comma.
|
// Insert the current entry followed by trailing comma.
|
||||||
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
|
(@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)*));
|
json_internal!(@object $object () ($($rest)*) ($($rest)*));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ macro_rules! json_internal {
|
|||||||
|
|
||||||
// Insert the last entry without trailing comma.
|
// Insert the last entry without trailing comma.
|
||||||
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
|
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
|
||||||
$object.insert(($($key)+).into(), $value);
|
let _ = $object.insert(($($key)+).into(), $value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Next value is `null`.
|
// Next value is `null`.
|
||||||
|
@ -1847,6 +1847,9 @@ fn test_json_macro() {
|
|||||||
(<Result<&str, ()> as Clone>::clone(&Ok("")).unwrap()): "ok",
|
(<Result<&str, ()> as Clone>::clone(&Ok("")).unwrap()): "ok",
|
||||||
(<Result<(), &str> as Clone>::clone(&Err("")).unwrap_err()): "err"
|
(<Result<(), &str> as Clone>::clone(&Err("")).unwrap_err()): "err"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[deny(unused_results)]
|
||||||
|
let _ = json!({ "architecture": [true, null] });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user