fix(autofmt): don't duplicate pretty continuation lines after multi-line source match#5546
Open
Not-Sarthak wants to merge 1 commit into
Open
fix(autofmt): don't duplicate pretty continuation lines after multi-line source match#5546Not-Sarthak wants to merge 1 commit into
Not-Sarthak wants to merge 1 commit into
Conversation
…ine source match When prettier_please breaks a statement at a different line position than the source did, the multi-line accumulator in write_partial_expr consumed every source line for the logical statement but the outer iterator kept walking pretty lines, re-emitting trailing continuations (e.g. `.clone();`) and advancing the source pointer past unrelated statements - producing invalid Rust. Convert pretty.lines() to a peekable iterator and, after emitting a multi-line verbatim source block whose accumulated content extends beyond the matched pretty line, consume the following pretty continuation lines whose content is already covered by the accumulated source. Fixes DioxusLabs#5523.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #5523.
dx fmtcorrupted RSX event handler blocks containing#[cfg]-gatedletbindings around amove |_|closure. When prettier_please broke a long statement at a different line position than the source did, the multi-line accumulator inwrite_partial_exprconsumed every source line for the logical statement but the outer iterator kept walking pretty lines, re-emitted the trailing continuation (.clone();), and advanced the source pointer past unrelated statements — producing invalid Rust:Fix
pretty.lines()→ peekable. After emitting a multi-line verbatim source block whose accumulated content extends beyond the matched pretty line, consume the pretty continuation lines whose content is already covered.Test plan
tests/samples/cfg_let_event_block.rsxwired intotwoway!cfg_let_event_block_is_idempotenttestcargo clippy --workspace --all-features --all-targets -- -D warningscleancargo fmt --all -- --checkcleancargo test --workspace --exclude dioxus-desktopclean (334 test bins, 0 failures)format!()macros) — all produce valid Rust