Skip to content

internal: add merge imports indent tests - #21319

Merged
A4-Tacks merged 1 commit into
rust-lang:masterfrom
A4-Tacks:merge-imports-indent
Jun 21, 2026
Merged

internal: add merge imports indent tests#21319
A4-Tacks merged 1 commit into
rust-lang:masterfrom
A4-Tacks:merge-imports-indent

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Dec 22, 2025

Copy link
Copy Markdown
Member

No description provided.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2025
@A4-Tacks
A4-Tacks marked this pull request as draft December 22, 2025 07:39
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2025
@A4-Tacks
A4-Tacks force-pushed the merge-imports-indent branch from 0d1109a to 7405f16 Compare December 22, 2025 10:08
@A4-Tacks
A4-Tacks marked this pull request as ready for review December 22, 2025 10:09
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2025
let make = SyntaxFactory::without_mappings();

let next_ws = self
let prev_ws = self

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this going to leave extra spaces in cases like this?

use foo; // to be removed

// other code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping whitespace in this case is also a reasonable solution. Do we need a fallback?

Usually, removing the whitespace before rather than after is more conducive to indentation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But uses specifically are commonly the first child and followed by a blank line. I don't see a reason to degrade one scenario for the other. If you handle both then fine.

@A4-Tacks A4-Tacks Mar 31, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But uses specifically are commonly the first child and followed by a blank line.

Uh, no, there are curly and whitespaces before it in ItemList, and there are often whitespaces before it in SourceFile as well

And the test utils will also add a whitespaces line at the beginning

If you handle both then fine.

If the siblings before and after are deleted, it may easily cause overlapping deletion when the caller batch deletes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A simple heuristic is: remove the previous, and if the use is the first child and has blank lines after it remove them as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In SourceFile, it is rare to truly remove all uses, so it is difficult to leave useless blank lines at the beginning of file

rustfmt will fix the indentation anyway for both ways. If you want to not need that, I won't stop you, but I don't want to regress other cases.

It's possible to make overlapping edits, isn't it?

Nope. It's a bug, I think it will even panic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope. It's a bug, I think it will even panic.

If it is possible to delete both the before and after uses when deleting a use, then this API will be difficult to use because many uses involve batch deletion of adjacent uses

I won't stop you, but I don't want to regress other cases.

Other cases are not common, and overall, this PR has improved trivias

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it is possible to delete both the before and after uses when deleting a use, then this API will be difficult to use because many uses involve batch deletion of adjacent uses

What API? Only this assist need to delete things correctly.

Other cases are not common, and overall, this PR has improved trivias

I've stated my opinion. @Veykril what is your opinion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Imo we shouldn't spend time on trying to fix whitespace at all as we cannot possibly get it right with the current infra without going through massive hoops. This all will be fixed by us having a proper formatter at some point.

People that do not use rustfmt simply have bad a time with r-a right now.

That is, we shouldn't try to fix indents, but newlines is a different matter though, as rustfmt does not necessarily normalize these. So we should check what happens with that here and if we regress in that regard or not, if yes we shouldn't do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At least for this assist, it replacing the first uses and deleting follows uses, there will be no blank line left on begin of file

I searched all the references, and only this one assist used this call, so there was no any regress

item
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does this code does? Please leave a comment.

@A4-Tacks
A4-Tacks force-pushed the merge-imports-indent branch from 7405f16 to 86e1c9d Compare March 24, 2026 08:11
@rustbot

This comment has been minimized.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Given @Veykril agrees with me this is not needed, I'll close this PR.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 5, 2026
@A4-Tacks

A4-Tacks commented Apr 6, 2026

Copy link
Copy Markdown
Member Author

But I noticed that there was no regress:

if we regress in that regard or not, if yes we shouldn't do this.

@A4-Tacks A4-Tacks reopened this Apr 13, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 13, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

@Veykril As I and @A4-Tacks seem to disagree what to do with this PR here, I'll leave it to your judgment as the team lead.

@rustbot

This comment has been minimized.

@A4-Tacks
A4-Tacks force-pushed the merge-imports-indent branch from 86e1c9d to 8cf59f5 Compare April 16, 2026 05:05
@rustbot

This comment has been minimized.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

@Veykril this is awaiting your decision.

@rustbot

This comment has been minimized.

@A4-Tacks
A4-Tacks force-pushed the merge-imports-indent branch from 8cf59f5 to b2df7c1 Compare June 20, 2026 17:34
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@A4-Tacks A4-Tacks changed the title Fix indent for merge_imports internal: add merge imports indent tests Jun 20, 2026
@A4-Tacks

Copy link
Copy Markdown
Member Author

It seems to have been fixed in #22351, I only retain tests

@Veykril
Veykril added this pull request to the merge queue Jun 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 21, 2026
@A4-Tacks
A4-Tacks added this pull request to the merge queue Jun 21, 2026
Merged via the queue into rust-lang:master with commit 69ccffd Jun 21, 2026
18 checks passed
@A4-Tacks
A4-Tacks deleted the merge-imports-indent branch June 21, 2026 08:29
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants