-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
parse_quote!
fails for Punctuated<Arm, Comma>
#1795
Comments
fn main() {
let i: Punctuated<Arm, Comma> = parse_quote!(
true => 12,,
false => 13,
);
println!{"{i:#?}"};
} is getting parsed, this is incorrect syntax but it "works"
I feel like the comma is part of the A simple idea would be to prioritize taking the trailing comma for the punctuated sequence rather than for the arm but I feel like this can lead to a number of other issues 🤔 |
The optional trailing comma is already included inside You can use |
Thank you for this, I didn't consider asking for let i: Vec<Attribute> = parse_quote!(
#[derive(Deserialize, Serialize)]
#[serde(transparent)]
); but let i: Vec<Arm> = parse_quote!(
true => 12
false => 13
); doesn't, let i: Vec<Arm> = parse_quote!(
true => 12,
false => 13
); does, assigning the comma to the first arm. It kinda messes things up when quoting back that let i: Vec<Arm> = parse_quote!(
true => 12,
false => 13,
);
println!{"{i:#?}"};
let b: Vec<Arm> = parse_quote!(
true => 12,
#(#i)*
);
println!{"{b:#?}"}; |
The repeat should not be adding new comma separators. The individual arms will already contain a trailing comma if required. Not all kinds of expressions in an arm require a trailing comma (the Rust grammar for this is complicated). If you are not sure whether arms have a comma, for example because you are combining arms from multiple parse_quote, then you could explicitly add a comma into all arms beforehand. |
Ok thank you 👌 |
this code (minimal example)
results in an error
Code is parsed properly when one arm is here, but the second you add another one it fails (trailing comma or not).
I'll clone syn and try to find why + a solution but would love some advices or a fix if someone already knows where the problem is
The text was updated successfully, but these errors were encountered: