Conversation
There was a problem hiding this comment.
I think it makes more sense to leave the comment where it was written instead of moving it outside the ;. Let's try to perserve that.
Let's also expand on the test cases. What about nested imports? For example:
use std {
sync::Arc /* some explanation */;
thread;
}There was a problem hiding this comment.
Even with normal // comments? For example:
use std // comment
;Should it stay like that or still move the comment outside the ;?
I think leaving the ; on its own line looks awkward.
There was a problem hiding this comment.
It's awkward to put a comment there in the first place. The best rustfmt can do is put the ; on the next line.
| use std // bye | ||
| ; |
There was a problem hiding this comment.
Let's include a mutli-single-line test case.
use std // some
// multi-line
// set of single comments
;|
Reminder, once the PR becomes ready for a review, use |
|
I think I addressed all requests. @rustbot ready |
| use std // comment | ||
| ; | ||
|
|
||
| use std /* comment */ ; |
There was a problem hiding this comment.
Two more test cases that I'm curious about. What if there's extra whitespace between the comment and the end of the use statement? How is that reformatted.
use std
// comment
;
use std
/* comment */
;| if self.span.is_dummy() || self.has_comment() { | ||
| return Ok(format!("{lhs};")); | ||
| } |
There was a problem hiding this comment.
Why are you using span.is_dummy()? I don't think that's used anywhere else in the codebase. How much of this PR was written with AI?
Fixes #7051.
Recovers comments located between the imported path and the terminating semicolon (e.g.
use std /* goodbye */;) on top-levelusestatements, preventing them from being dropped.Includes regression tests in
tests/source/issue-7051.rs.