File tree 4 files changed +26
-5
lines changed
4 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,11 @@ macro_rules! json_internal {
224
224
json_internal!( @object $object ( $key) ( : $( $rest) * ) ( : $( $rest) * ) ) ;
225
225
} ;
226
226
227
+ // Refuse to absorb colon token into key expression.
228
+ ( @object $object: ident ( $( $key: tt) * ) ( : $( $unexpected: tt) +) $copy: tt) => {
229
+ json_expect_expr_comma!( $( $unexpected) +) ;
230
+ } ;
231
+
227
232
// Munch a token into the current key.
228
233
( @object $object: ident ( $( $key: tt) * ) ( $tt: tt $( $rest: tt) * ) $copy: tt) => {
229
234
json_internal!( @object $object ( $( $key) * $tt) ( $( $rest) * ) ( $( $rest) * ) ) ;
@@ -290,3 +295,9 @@ macro_rules! json_internal_vec {
290
295
macro_rules! json_unexpected {
291
296
( ) => { } ;
292
297
}
298
+
299
+ #[ macro_export]
300
+ #[ doc( hidden) ]
301
+ macro_rules! json_expect_expr_comma {
302
+ ( $e: expr , $( $tt: tt) * ) => { } ;
303
+ }
Original file line number Diff line number Diff line change
1
+ use serde_json:: json;
2
+
3
+ fn main ( ) {
4
+ json ! ( { "1" : "" "2" : "" } ) ;
5
+ }
Original file line number Diff line number Diff line change
1
+ error: no rules expected the token `"2"`
2
+ --> $DIR/missing_comma.rs:4:21
3
+ |
4
+ 4 | json!({ "1": "" "2": "" });
5
+ | -^^^ no rules expected this token in macro call
6
+ | |
7
+ | help: missing comma here
Original file line number Diff line number Diff line change 1
- error: unexpected end of macro invocation
2
- --> $DIR/parse_expr.rs:4:5
1
+ error: no rules expected the token `~`
2
+ --> $DIR/parse_expr.rs:4:19
3
3
|
4
4
4 | json!({ "a" : ~ });
5
- | ^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
6
- |
7
- = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5
+ | ^ no rules expected this token in macro call
You can’t perform that action at this time.
0 commit comments