Skip to content
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

rustfix: Support inserting new lines. #13226

Merged
merged 4 commits into from
Jan 2, 2024
Merged

Commits on Dec 31, 2023

  1. Cleanup rustfix parse_and_replace test.

    This is just some minor code cleanup for the parse_and_replace test,
    there should not be any functional differences.
    ehuss committed Dec 31, 2023
    Configuration menu
    Copy the full SHA
    c54fa88 View commit details
    Browse the repository at this point in the history
  2. Add a primitive way to add new tests to parse_and_replace.

    This adds an environment variable to make it easier to add new tests.
    ehuss committed Dec 31, 2023
    Configuration menu
    Copy the full SHA
    029fe2b View commit details
    Browse the repository at this point in the history
  3. rustfix: Support inserting new lines.

    If rustfix received a suggestion which inserts new lines without
    replacing existing lines, it would ignore the suggestion. This is
    because `parse_snippet` would immediately return if the `lines` to
    replace was empty.
    
    The solution here is to just drop the code which messes with the
    original text line. `cargo fix` (and compiletest) currently do not use
    this. This was originally added back in the days when rustfix supported
    an interactive UI which showed color highlighting of what it looks like
    with the replacement. My feeling is that when we add something like this
    back in, I would prefer to instead use a real diff library and display
    instead of trying to do various text manipulation for display. This
    particular code has generally been buggy, and has been a problem several
    times.
    
    The included test fails without this fix because the changes do not
    apply, and the code cannot compile.
    ehuss committed Dec 31, 2023
    Configuration menu
    Copy the full SHA
    a21997f View commit details
    Browse the repository at this point in the history

Commits on Jan 1, 2024

  1. Handle Windows newlines.

    Suggestions that come from rustc that are multi-line only use LF line
    endings. But if the file is checked out on windows with CRLF
    line-endings, then you end up with a mix of line endings that don't
    match the "fixed.rs" file.
    
    Tracking this at rust-lang/rust#119482.
    ehuss committed Jan 1, 2024
    Configuration menu
    Copy the full SHA
    3d3e1b3 View commit details
    Browse the repository at this point in the history