Skip to content

Commit e976482

Browse files
committed
Change map-capacity-counting part of json_internal! macro to not report errors.
Since these errors are already reported by the part of the macro that actually parses the map, it is unnecessary to report them twice, so the capacity-counting part can just return 0 if it encounters an error.
1 parent 99629eb commit e976482

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/macros.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ macro_rules! json_internal {
254254
1 + json_internal!(@object_capacity () ($($rest)*) ($($rest)*))
255255
};
256256

257-
// Current entry followed by unexpected token. The actual parsing macro will print the error message.
257+
// Current entry followed by unexpected token. The part that parses the values
258+
// will trigger a reasonable error message; here, we just return 0
259+
// so that there is not a duplicated error message.
258260
(@object_capacity entry $unexpected:tt $($rest:tt)*) => {
259261
0
260262
};
@@ -299,22 +301,30 @@ macro_rules! json_internal {
299301
json_internal!(@object_capacity entry)
300302
};
301303

302-
// Missing value for last entry. The actual parsing macro will print the error message.
304+
// Missing value for last entry. The part that parses the values
305+
// will trigger a reasonable error message; here, we just return 0
306+
// so that there is not a duplicated error message.
303307
(@object_capacity ($($key:tt)+) (:) $copy:tt) => {
304308
0
305309
};
306310

307-
// Missing colon and value for last entry. The actual parsing macro will print the error message.
311+
// Missing colon and value for last entry. The part that parses the values
312+
// will trigger a reasonable error message; here, we just return 0
313+
// so that there is not a duplicated error message.
308314
(@object_capacity ($($key:tt)+) () $copy:tt) => {
309315
0
310316
};
311317

312-
// Misplaced colon. The actual parsing macro will print the error message.
318+
// Misplaced colon. The part that parses the values
319+
// will trigger a reasonable error message; here, we just return 0
320+
// so that there is not a duplicated error message.
313321
(@object_capacity () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
314322
0
315323
};
316324

317-
// Found a comma inside a key. The actual parsing macro will print the error message.
325+
// Found a comma inside a key. The part that parses the values
326+
// will trigger a reasonable error message; here, we just return 0
327+
// so that there is not a duplicated error message.
318328
(@object_capacity ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
319329
0
320330
};
@@ -326,8 +336,10 @@ macro_rules! json_internal {
326336
// };
327337

328338
// Refuse to absorb colon token into key expression.
339+
// The part that parses the values will trigger a reasonable error message;
340+
// here, we just return 0 so that there is not a duplicated error message.
329341
(@object_capacity ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
330-
json_expect_expr_comma!($($unexpected)+)
342+
0
331343
};
332344

333345
// Munch a token into the current key.

0 commit comments

Comments
 (0)