mirror of
https://github.com/serde-rs/json.git
synced 2025-09-30 06:21:34 +00:00
Improve error message of unexpected colon or comma in json macro
These rules regressed when the unimplemented macro began accepting formatter arguments.
This commit is contained in:
parent
f12c983942
commit
25b5dfbb6c
@ -216,13 +216,13 @@ macro_rules! json_internal {
|
||||
// Misplaced colon. Trigger a reasonable error message.
|
||||
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
|
||||
// Takes no arguments so "no rules expected the token `:`".
|
||||
unimplemented!($colon);
|
||||
json_unexpected!($colon);
|
||||
};
|
||||
|
||||
// Found a comma inside a key. Trigger a reasonable error message.
|
||||
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
|
||||
// Takes no arguments so "no rules expected the token `,`".
|
||||
unimplemented!($comma);
|
||||
json_unexpected!($comma);
|
||||
};
|
||||
|
||||
// Key is fully parenthesized. This avoids clippy double_parens false
|
||||
@ -280,3 +280,9 @@ macro_rules! json_internal {
|
||||
$crate::to_value(&$other).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! json_unexpected {
|
||||
() => {};
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected expression, found `:`
|
||||
error: no rules expected the token `:`
|
||||
--> $DIR/unexpected_colon.rs:13:13
|
||||
|
|
||||
13 | json!({ : true });
|
||||
| ^ expected expression
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected expression, found `,`
|
||||
error: no rules expected the token `,`
|
||||
--> $DIR/unexpected_comma.rs:13:17
|
||||
|
|
||||
13 | json!({ "a" , "b": true });
|
||||
| ^ expected expression
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user