-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Determine when new comment lines are needed for itemized blocks
Fixes 5088 Previously, rustfmt would add a new comment line anytime it reformatted an itemized block within a comment when ``wrap_comments=true``. This would lead to rustfmt adding empty comments with trailing whitespace. Now, new comment lines are only added if the original comment spanned multiple lines, if the comment needs to be wrapped, or if the comment originally started with an empty comment line.
- Loading branch information
1 parent
1f28683
commit ec46ffd
Showing
18 changed files
with
424 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/source/issue-5088/deeply_nested_long_comment_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
fn main() { | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
// - aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc | ||
|
||
// * aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc | ||
|
||
/* - aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc */ | ||
|
||
/* * aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc */ | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
19 changes: 19 additions & 0 deletions
19
...source/issue-5088/start_with_empty_comment_very_long_itemized_block_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
// | ||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
// | ||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
/* | ||
* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* | ||
* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
|
||
/* | ||
* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* | ||
* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ |
13 changes: 13 additions & 0 deletions
13
tests/source/issue-5088/very_long_comment_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
/* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
|
||
/* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ |
33 changes: 33 additions & 0 deletions
33
tests/target/issue-5088/deeply_nested_long_comment_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
fn main() { | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
// - aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc | ||
|
||
// * aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc | ||
|
||
/* - aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc */ | ||
|
||
/* * aaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa aaaaaaaaa bbbbbbbbbb bbbbbbbbb bbbbbbbbb ccc cccccccccc ccccccc cccccccc */ | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/target/issue-5088/deeply_nested_long_comment_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
fn main() { | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
{ | ||
// - aaaa aaaaaaaaa aaaaaaaaa | ||
// aaaaaaaaa aaaaaaaaa | ||
// bbbbbbbbbb bbbbbbbbb | ||
// bbbbbbbbb ccc cccccccccc | ||
// ccccccc cccccccc | ||
|
||
// * aaaa aaaaaaaaa aaaaaaaaa | ||
// aaaaaaaaa aaaaaaaaa | ||
// bbbbbbbbbb bbbbbbbbb | ||
// bbbbbbbbb ccc cccccccccc | ||
// ccccccc cccccccc | ||
|
||
/* - aaaa aaaaaaaaa aaaaaaaaa | ||
* aaaaaaaaa aaaaaaaaa | ||
* bbbbbbbbbb bbbbbbbbb | ||
* bbbbbbbbb ccc cccccccccc | ||
* ccccccc cccccccc */ | ||
|
||
/* * aaaa aaaaaaaaa aaaaaaaaa | ||
* aaaaaaaaa aaaaaaaaa | ||
* bbbbbbbbbb bbbbbbbbb | ||
* bbbbbbbbb ccc cccccccccc | ||
* ccccccc cccccccc */ | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/target/issue-5088/multi_line_itemized_block_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
// - some itemized block 1 | ||
// - some itemized block 2 | ||
|
||
// * some itemized block 3 | ||
// * some itemized block 4 | ||
|
||
/* | ||
* - some itemized block 5 | ||
* - some itemized block 6 | ||
*/ | ||
|
||
/* | ||
* * some itemized block 7 | ||
* * some itemized block 8 | ||
*/ |
17 changes: 17 additions & 0 deletions
17
tests/target/issue-5088/multi_line_itemized_block_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
// - some itemized block 1 | ||
// - some itemized block 2 | ||
|
||
// * some itemized block 3 | ||
// * some itemized block 4 | ||
|
||
/* | ||
* - some itemized block 5 | ||
* - some itemized block 6 | ||
*/ | ||
|
||
/* | ||
* * some itemized block 7 | ||
* * some itemized block 8 | ||
*/ |
37 changes: 37 additions & 0 deletions
37
tests/target/issue-5088/multi_line_text_with_itemized_block_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
// Some text | ||
// - some itemized block 1 | ||
// - some itemized block 2 | ||
// Some more text | ||
// - some itemized block 3 | ||
// - some itemized block 4 | ||
// Even more text | ||
|
||
// Some text | ||
// * some itemized block 5 | ||
// * some itemized block 6 | ||
// Some more text | ||
// * some itemized block 7 | ||
// * some itemized block 8 | ||
// Even more text | ||
|
||
/* | ||
* Some text | ||
* - some itemized block 9 | ||
* - some itemized block 10 | ||
* Some more text | ||
* - some itemized block 11 | ||
* - some itemized block 12 | ||
* Even more text | ||
*/ | ||
|
||
/* | ||
* Some text | ||
* * some itemized block 13 | ||
* * some itemized block 14 | ||
* Some more text | ||
* * some itemized block 15 | ||
* * some itemized block 16 | ||
* Even more text | ||
*/ |
37 changes: 37 additions & 0 deletions
37
tests/target/issue-5088/multi_line_text_with_itemized_block_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
// Some text | ||
// - some itemized block 1 | ||
// - some itemized block 2 | ||
// Some more text | ||
// - some itemized block 3 | ||
// - some itemized block 4 | ||
// Even more text | ||
|
||
// Some text | ||
// * some itemized block 5 | ||
// * some itemized block 6 | ||
// Some more text | ||
// * some itemized block 7 | ||
// * some itemized block 8 | ||
// Even more text | ||
|
||
/* | ||
* Some text | ||
* - some itemized block 9 | ||
* - some itemized block 10 | ||
* Some more text | ||
* - some itemized block 11 | ||
* - some itemized block 12 | ||
* Even more text | ||
*/ | ||
|
||
/* | ||
* Some text | ||
* * some itemized block 13 | ||
* * some itemized block 14 | ||
* Some more text | ||
* * some itemized block 15 | ||
* * some itemized block 16 | ||
* Even more text | ||
*/ |
9 changes: 9 additions & 0 deletions
9
tests/target/issue-5088/single_line_itemized_block_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
// - some itemized block 1 | ||
|
||
// * some itemized block 2 | ||
|
||
/* - some itemized block 3 */ | ||
|
||
/* * some itemized block 4 */ |
9 changes: 9 additions & 0 deletions
9
tests/target/issue-5088/single_line_itemized_block_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
// - some itemized block 1 | ||
|
||
// * some itemized block 2 | ||
|
||
/* - some itemized block 3 */ | ||
|
||
/* * some itemized block 4 */ |
19 changes: 19 additions & 0 deletions
19
...arget/issue-5088/start_with_empty_comment_very_long_itemized_block_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
// | ||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
// | ||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
|
||
/* | ||
* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* | ||
* - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
|
||
/* | ||
* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ | ||
/* | ||
* * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.*/ |
Oops, something went wrong.