refactor: keep attr-only statements and cloned lets printable #1457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Several transforms (
sink_lets,fold_let_assign,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