-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error message for use of a keyword in ident position could be tweaked #15358
Comments
However, I think the error message could be improved to include a reference to "keyword", e.g. Repurposing the bug for this behaviour. (Thanks for filing!) |
(I believe the idiomatic way to use a keyword as an identifier is adding a trailing |
@huonw Yes, that's the typical pattern. Humorous aside: the main exception I've seen is |
Heh, maybe we should use |
The thing is, i'm using this structure for JSON de/serializing and i cant remove the type field, is there any way to make serialize crate drop the field 'type' in a field say '_type'? |
Not yet, unfortunately. #14268 is related. |
Well, that means rust is not an option for me now :( |
I misspoke: the situation is slightly more subtle than just "no". There's currently no way to get the automatic // foo.rs
#[deriving(Encodable, Decodable)]
struct Serie {
metric: String,
type_: String
}
struct Serie {
metric: String,
type_: String,
}
impl <__D: ::serialize::Decoder<__E>, __E> ::serialize::Decodable<__D, __E>
for Serie {
fn decode(__arg_0: &mut __D) -> ::std::result::Result<Serie, __E> {
__arg_0.read_struct("Serie", 2u,
|_d|
::std::result::Ok(Serie{metric:
match _d.read_struct_field("metric",
0u,
|_d|
::serialize::Decodable::decode(_d))
{
Ok(__try_var)
=> __try_var,
Err(__try_var)
=>
return Err(__try_var)
},
type_:
match _d.read_struct_field("type_",
1u,
|_d|
::serialize::Decodable::decode(_d))
{
Ok(__try_var)
=> __try_var,
Err(__try_var)
=>
return Err(__try_var)
},}))
}
}
impl <__S: ::serialize::Encoder<__E>, __E> ::serialize::Encodable<__S, __E>
for Serie {
fn encode(&self, __arg_0: &mut __S) -> ::std::result::Result<(), __E> {
match *self {
Serie{metric: ref __self_0_0, type_: ref __self_0_1} =>
__arg_0.emit_struct("Serie", 2u, |_e| {
match _e.emit_struct_field("metric", 0u,
|_e|
(*__self_0_0).encode(_e))
{
Ok(__try_var) => __try_var,
Err(__try_var) => return Err(__try_var)
};
return _e.emit_struct_field("type_", 1u,
|_e|
(*__self_0_1).encode(_e));
})
}
}
} The |
@huonw Awesome! will try that as soon as i can, thanks a lot! |
Add triagebot no-merges config cc rust-lang/triagebot#1704 rust-lang#114157
I use different approch, but it works in best way
here
type_ will convert to type while Deserialize the struct |
In the example below, the error message could at least mention that
type
is keyword, or be changed more radically: #15358 (comment)Previously:
Cannot declare a field 'type' on struct
Declaring for example the following struct:
Yields the following error:
Is this intended?
The text was updated successfully, but these errors were encountered: