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

Delete line if suggestion would replace it with an empty line #120305

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

clubby789
Copy link
Contributor

Fixes #120296

@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2024

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 24, 2024
@clubby789 clubby789 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 24, 2024
@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2024
@rust-cloud-vms rust-cloud-vms bot force-pushed the unused-import-line branch 2 times, most recently from 0daae5c to dc5a11b Compare January 24, 2024 13:00
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is a way to address this specific issue, it might be a better idea to modify rustc_errors::json::DiagnosticSpan::from_span_full to have this logic of checking "does this span end on the last char of a line, followed by \n? if extend the span by one byte". Doing it there doesn't change how the diff is shown in diagnostics, but aids rustfix not have to care about this and doesn't require us to address these kind of spans in every suggestion we produce.

@clubby789
Copy link
Contributor Author

Doing that globally seems to break a lot of .fixed tests:

diff --git a/tests/ui/binop/false-binop-caused-by-missing-semi.fixed b/tests/ui/binop/false-binop-caused-by-missing-semi.fixed
index b47372c9064..441fad80c8f 100644
--- a/tests/ui/binop/false-binop-caused-by-missing-semi.fixed
+++ b/tests/ui/binop/false-binop-caused-by-missing-semi.fixed
@@ -3,8 +3,7 @@ fn foo() {}
 fn main() {
     let mut y = 42;
     let x = &mut y;
-    foo();
-    *x = 0;  //~ ERROR invalid left-hand side of assignment
+    foo();    *x = 0;  //~ ERROR invalid left-hand side of assignment
     let _ = x;
     println!("{y}");
 }
diff --git a/tests/ui/block-result/consider-removing-last-semi.fixed b/tests/ui/block-result/consider-removing-last-semi.fixed
index 36a769fe529..931a5440b79 100644
--- a/tests/ui/block-result/consider-removing-last-semi.fixed
+++ b/tests/ui/block-result/consider-removing-last-semi.fixed
@@ -2,19 +2,16 @@
 
 pub fn f() -> String {  //~ ERROR mismatched types
     0u8;
-    "bla".to_string()
-}
+    "bla".to_string()}
 
 pub fn g() -> String {  //~ ERROR mismatched types
     "this won't work".to_string();
-    "removeme".to_string()
-}
+    "removeme".to_string()}
 
 pub fn macro_tests() -> u32 {  //~ ERROR mismatched types
     macro_rules! mac {
         () => (1);
     }
-    mac!()
-}
+    mac!()}```

@estebank
Copy link
Contributor

estebank commented Jan 24, 2024

@clubby789 what happens if you only do the span extension if the replacement is ""? An alternative heuristic could be to see if the start column is 0 as well...

@clubby789 clubby789 changed the title Remove rest of line in unused_import fix if there is nothing else Delete line if suggestion would replace it with an empty line Jan 26, 2024
@clubby789
Copy link
Contributor Author

Catches a lot more cases 👀 Good idea!

@clubby789 clubby789 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 26, 2024
@rust-log-analyzer

This comment has been minimized.

@clubby789
Copy link
Contributor Author

Actually this could do with some improvement
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 26, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@bors
Copy link
Collaborator

bors commented Mar 1, 2024

☔ The latest upstream changes (presumably #121810) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase and I'll approve

@estebank estebank self-assigned this Mar 1, 2024
@petrochenkov petrochenkov removed their assignment Mar 1, 2024
@rust-cloud-vms rust-cloud-vms bot force-pushed the unused-import-line branch from 799a810 to 367126d Compare March 1, 2024 13:48
@clubby789
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 1, 2024
@estebank
Copy link
Contributor

estebank commented Mar 1, 2024

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 1, 2024

📌 Commit 367126d has been approved by estebank

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2024
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#111505 (Made `INVALID_DOC_ATTRIBUTES` lint deny by default)
 - rust-lang#120305 (Delete line if suggestion would replace it with an empty line)
 - rust-lang#121153 (Suggest removing superfluous semicolon when statements used as expression)
 - rust-lang#121497 (`-Znext-solver=coherence`: suggest increasing recursion limit)
 - rust-lang#121634 (Clarify behavior of slice prefix/suffix operations in case of equality)
 - rust-lang#121706 (match lowering: Remove hacky branch in sort_candidate)
 - rust-lang#121730 (Add profiling support to AIX)
 - rust-lang#121750 (match lowering: Separate the `bool` case from other integers in `TestKind`)
 - rust-lang#121803 (Never say "`Trait` is implemented for `{type error}`")
 - rust-lang#121811 (Move sanitizer ui tests to sanitizer directory)
 - rust-lang#121824 (Implement missing ABI structures in StableMIR)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3c89280 into rust-lang:master Mar 2, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 2, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2024
Rollup merge of rust-lang#120305 - clubby789:unused-import-line, r=estebank

Delete line if suggestion would replace it with an empty line

Fixes rust-lang#120296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo fix on unused use statements leaves empty lines behind.
6 participants