-
Notifications
You must be signed in to change notification settings - Fork 281
refactor: keep attr-only statements and cloned lets printable #1457
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
base: master
Are you sure you want to change the base?
Conversation
fw-immunant
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. Is there an easy way to observe the change in behavior? It would be nice to have a test case if possible.
ahomescu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try this together with #1433?
| /// Pick the span we should attach to a freshly minted statement. | ||
| /// | ||
| /// We want new statements produced by transforms such as `sink_lets` or | ||
| /// `fold_let_assign` to retain the source span of the code they were cloned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just fix the transforms then? Why couldn't they pass in the spans?
86b24c2 to
f294de7
Compare
|
@ahomescu @fw-immunant I'm trying a different approach in #1469 based on this comment. If that looks good, I'll merge it and close this one
|
Several transforms (
sink_lets,remove_redundant_let_types) were panicking whenever the rewrite engine had to reparse snippets that no longer looked like full Rust statements.Two cases showed up when testing:
#[derive]lines, the transform temporarily splices only the attribute text (for example just#[derive(Copy, Clone)]) while the enclosing struct body is rewritten at a higher level. Rust’s parser refuses that input, soPrintParse<Stmt>panicked before recovery finishedletbindings inherit the builder’s defaultDUMMY_SP, so pretty-printing emits an empty string even though the original code had a real initializer. The AST/text round-trip fails and subsequent rewrites abortThis PR:
PrintParse<Stmt>up front, reparses them by temporarily appending a dummy struct, and returns aStmtKind::Emptythat carries the combined attribute span, which keeps the rewriter from panicking while the surrounding struct/item is printed elsewhereDUMMY_SP. Newly cloned locals/exprs retain their original source ranges, sorewrite_at_implcan pull real snippets instead of an empty buffer