mirror of
https://github.com/serde-rs/json.git
synced 2025-10-02 15:26:00 +00:00
Prevent type ascription misdiagnosis
This commit is contained in:
parent
4a948df6f6
commit
0443daa488
@ -224,6 +224,11 @@ macro_rules! json_internal {
|
|||||||
json_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
|
json_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Refuse to absorb colon token into key expression.
|
||||||
|
(@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => {
|
||||||
|
json_expect_expr_comma!($($unexpected)+);
|
||||||
|
};
|
||||||
|
|
||||||
// Munch a token into the current key.
|
// Munch a token into the current key.
|
||||||
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
|
||||||
json_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
|
json_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
|
||||||
@ -290,3 +295,9 @@ macro_rules! json_internal_vec {
|
|||||||
macro_rules! json_unexpected {
|
macro_rules! json_unexpected {
|
||||||
() => {};
|
() => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! json_expect_expr_comma {
|
||||||
|
($e:expr ,) => {};
|
||||||
|
}
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
error: expected type, found `""`
|
error: no rules expected the token `"2"`
|
||||||
--> $DIR/missing_comma.rs:4:18
|
--> $DIR/missing_comma.rs:4:21
|
||||||
|
|
|
|
||||||
4 | json!({ "1": "" "2": "" });
|
4 | json!({ "1": "" "2": "" });
|
||||||
| - ^^ expected type
|
| ^^^ no rules expected this token in macro call
|
||||||
| |
|
|
||||||
| tried to parse a type due to this type ascription
|
|
||||||
|
|
|
||||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
|
||||||
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
error: unexpected end of macro invocation
|
error: no rules expected the token `~`
|
||||||
--> $DIR/parse_expr.rs:4:5
|
--> $DIR/parse_expr.rs:4:19
|
||||||
|
|
|
|
||||||
4 | json!({ "a" : ~ });
|
4 | json!({ "a" : ~ });
|
||||||
| ^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
| ^ no rules expected this token in macro call
|
||||||
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user