rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Keep the comment after where clause that has no predicate (#4649)

Open ChinYing-Li opened this issue 4 years ago • 4 comments

The pull request aims at solving #4649, and formats the comment that occurs before the where-clause; two cases are handled by the modified code:

  • where exists but does not have any predicate: For this scenario, it would be great to have people's input on
  1. the indent of the comment
  2. If we always put the comment in a new line (the current behavior is to always add \n right after where). Several test cases in issue_4649.rs would fail.
  • where does not exist. In this scenario, rustfmt behaves the same as before.

Any suggestion is appreciated!

ChinYing-Li avatar Mar 28 '21 10:03 ChinYing-Li

Now that I looked through other place where where is formatted, perhaps we should create a function format_comment_after_where to be used?

ChinYing-Li avatar Mar 29 '21 09:03 ChinYing-Li

If we use the approach in this PR to format where clause in all scenarios, I think #4672 can also be resolved.

ChinYing-Li avatar Apr 11 '21 00:04 ChinYing-Li

Looks like this now has a lot of CI/test failures. Could you please take a look when you get a chance?

calebcartwright avatar Apr 11 '21 16:04 calebcartwright

The idempotent tests were ran against two different config; the current failure output looks like theis:

Mismatch at tests/source/issue-4649.rs:7:
 
     fn bar2(&self, a: T)
     where
-        /* Self: Bar */;
+ /* Self: Bar */;
 }
 

Mismatch at tests/source/issue-4001.rs:1:
 fn unit() -> ()
 where
-    /* comment */ {
+ /* comment */ {
     ()
 }

But if I change the target snippet to match the outcome above, the failure output became:

Mismatch at tests/source/issue-4649.rs:7:
 
     fn bar2(&self, a: T)
     where
-  /* Self: Bar */;
+ /* Self: Bar */;
 }
 

Mismatch at tests/target/issue-4649.rs:7:
 
     fn bar2(&self, a: T)
     where
-  /* Self: Bar */;
+        /* Self: Bar */;
 }
 

Mismatch at tests/source/issue-4001.rs:1:
 fn unit() -> ()
 where
-  /* comment */ {
+ /* comment */ {
     ()
 }
 

Mismatch at tests/target/issue-4001.rs:1:
 fn unit() -> ()
 where
-  /* comment */ {
+    /* comment */ {
     ()
 }

What are some way to circumvent this?

ChinYing-Li avatar Apr 12 '21 09:04 ChinYing-Li