-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
This is just some minor code cleanup for the parse_and_replace test, there should not be any functional differences.
This adds an environment variable to make it easier to add new tests.
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.
r? @weihanglo (rustbot has picked a reviewer for you, use r? to override) |
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.
@@ -20,6 +42,7 @@ mod settings { | |||
pub const CHECK_JSON: &str = "RUSTFIX_TEST_CHECK_JSON"; | |||
pub const RECORD_JSON: &str = "RUSTFIX_TEST_RECORD_JSON"; | |||
pub const RECORD_FIXED_RUST: &str = "RUSTFIX_TEST_RECORD_FIXED_RUST"; | |||
pub const BLESS: &str = "RUSTFIX_TEST_BLESS"; |
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.
This makes me wonder if we should use snapbox
to minimize the custom logic here.
Thank you. Going to merge this soon. @bors r+ |
☀️ Test successful - checks-actions |
Update cargo 11 commits in ac6bbb33293d8d424c17ecdb42af3aac25fb7295..add15366eaf3f3eb84717d3b8b71902ca36a7c84 2023-12-26 23:22:08 +0000 to 2024-01-02 03:24:42 +0000 - chore(deps): update gix (rust-lang/cargo#13230) - chore(deps): update alpine docker tag to v3.19 (rust-lang/cargo#13228) - rustfix: Support inserting new lines. (rust-lang/cargo#13226) - Fix fix::fix_in_dependency to not rely on rustc (rust-lang/cargo#13220) - cleanup: Remove error-format special-case in `cargo fix` (rust-lang/cargo#13224) - `cargo fix`: always inherit the jobserver (rust-lang/cargo#13225) - Bump cargo-credential to 0.4.3 (rust-lang/cargo#13221) - `cargo add` - fix for adding features from repository with multiple packages. (rust-lang/cargo#13213) - Remove repetitive words (rust-lang/cargo#13216) - Add cargo:rustc-cdylib-link-arg into RESERVED_PREFIXES list (rust-lang/cargo#13212) - chore(doc): doc for custom subcommands look up. (rust-lang/cargo#13203)
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 thelines
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.
This also includes a little bit of cleanup for the
parse_and_replace
test. My feeling is that this test could use further improvements.