We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
prettyplease will generate rust code that does not accurately reflect the Expr tree that goes into it. There is a workaround using to_token_stream.
to_token_stream
let mut file = syn::File { shebang: None, attrs: vec![], items: vec![], }; let mut func: syn::ItemFn = parse_quote!(fn foo(n: i32) -> i32 { }); let lhs: syn:Expr = parse_quote!(n + n); let rhs: syn:Expr = parse_quote!(n + n); func.block.stmts.push( syn::ExprBinary { attrs: vec![], op: parse_quote!(*), left: Box::new(lhs), right: Box::new(rhs), } .into() ); let pretty_direct = prettyplease::unparse(&file); // INCORRECT: fn foo(n: i32) -> i32 { n + n * n + n } let munged: syn::File = syn::parse2(rust.to_token_stream()).unwrap(); let pretty_indirect = prettyplease::unparse(&munged)).unwrap(); // CORRECT: fn foo(n: i32) -> i32 { (n + n) * (n + n) }
Apologies if this doesn't quite compile, but it should give you the general gist of the issue.
The text was updated successfully, but these errors were encountered:
Do the owners consider this a bug? If so, would they be amenable to PRs fixing it?
Sorry, something went wrong.
No branches or pull requests
prettyplease will generate rust code that does not accurately reflect the Expr tree that goes into it. There is a workaround using
to_token_stream
.Apologies if this doesn't quite compile, but it should give you the general gist of the issue.
The text was updated successfully, but these errors were encountered: