-
Notifications
You must be signed in to change notification settings - Fork 930
Backport #4572 - Proper indentation of multiline post-comments in a list #5649
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
Open
davidBar-On
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
davidBar-On:issue-4546-backport-4572-proper_indentation_of_multiline_post-comments_in_a_list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,163 @@ | ||
// Basic tests (using vectors) - list multiline post-comment is indented on its own | ||
fn main() { | ||
let v = [ | ||
"A", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
]; | ||
} | ||
|
||
fn main() { | ||
let v = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
]; | ||
} | ||
|
||
// Tests for Struct | ||
pub(crate) struct ListFormatting<'a> { | ||
tactic: DefinitiveListTactic, | ||
separator: &'a str, /* Comment */ | ||
trailing_separator: SeparatorTactic, /* Comment */ | ||
separator_place: SeparatorPlace, // Comment 1 | ||
// Comment 2 | ||
shape: Shape, /* Non-expressions, e.g., items, will have a new line at the end of the list. | ||
* Important for comment styles. */ | ||
ends_with_newline: bool, // Remove newlines between list elements for expressions. | ||
preserve_newline: bool, // Nested import lists get some special handling for the "Mixed" list type | ||
nested: bool, | ||
// Whether comments should be visually aligned. | ||
align_comments: bool, /* comment */ | ||
config: &'a Config, | ||
} | ||
|
||
fn main() { | ||
l = ListItem { | ||
pre_comment, /* Comment */ | ||
pre_comment_style, /* Multiline comment | ||
* Line 2 */ | ||
/* New line comment */ | ||
item: if self.inner.peek().is_none() && self.leave_last { /* Comment */ | ||
None | ||
} else { | ||
(self.get_item_string)(&item) | ||
}, | ||
post_comment, /* Comment */ | ||
new_lines, /* Comment */ | ||
} | ||
} | ||
|
||
// Test for Function parameters | ||
pub(crate) fn new(shape: Shape, config: &'a Config) -> Self { | ||
ListFormatting { | ||
tactic: DefinitiveListTactic::Vertical, /* Comment */ | ||
separator: ",", /* comment */ | ||
trailing_separator: SeparatorTactic::Never, /* Multiline comment | ||
* second comment line */ | ||
separator_place: SeparatorPlace::Back, // A longggggggggggggggggggggggggggggggggggggggggggggggggggg comment | ||
shape, | ||
/* New line comment */ | ||
ends_with_newline: true, /* Comment */ | ||
preserve_newline: false, /* Comment */ | ||
nested: false, /* Comment */ | ||
align_comments: true, /* Another Multiline comment | ||
* second comment line */ | ||
config, /* Last comment */ | ||
} | ||
} | ||
|
||
// Test for `where` | ||
impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3> | ||
where | ||
I: Iterator<Item = T>, /* Comment */ | ||
F111111111: Fn(&T) -> BytePos, /* Comment */ | ||
F2222222: Fn(&T) -> BytePos, /* Multiline comment | ||
* Line 2 */ | ||
F3: Fn(&T) -> Option<String>, /* Comment */ | ||
{} | ||
|
||
// Test for some types of lists | ||
pub(crate) fn itemize_list<'a, T, I, F1, F2, F3>( | ||
snippet_provider: &'a SnippetProvider, /* Comment */ | ||
inner: I, /* Comment */ | ||
terminator: &'a str, /* Multiline comment | ||
* Line 2 */ | ||
separator: &'a str, /* Comment */ | ||
get_lo: F1, /* Comment */ | ||
get_hi: F2, | ||
get_item_string: F3, /* Comment */ | ||
prev_span_end: BytePos, /* Multiline comment | ||
* Line 2 */ | ||
next_span_start: BytePos, /* Comment */ | ||
leave_last: bool, | ||
) -> ListItems<'a, I, F1, F2, F3> | ||
where | ||
I: Iterator<Item = T>, /* Comment */ | ||
F111111111: Fn(&T) -> BytePos, /* Multiline comment | ||
* Line 2 */ | ||
F2222222: Fn(&T) -> BytePos, | ||
F3: Fn(&T) -> Option<String>, /* Comment */ | ||
{ | ||
ListItems {/* Comment to ListItems */ | ||
snippet_provider, /* Multiline comment | ||
* Line 2 */ | ||
inner: inner.peekable(), /* Another multiline comment | ||
* another Line 2 */ | ||
get_lo, /* Comment */ | ||
get_hi, | ||
get_item_string, | ||
prev_span_end, /* Comment */ | ||
next_span_start,/* Comment */ | ||
terminator, | ||
separator, /* Yet another multiline comment | ||
* yet another Line 2 */ | ||
leave_last,/* Comment */ | ||
} | ||
} | ||
|
||
|
||
// Tests when comment in the same line of the item will exceed line width | ||
fn main() { | ||
let v = [ | ||
"A-Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item A comment */ | ||
"BBB", /* item B Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D-Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
]; | ||
} | ||
|
||
// Test for nested items | ||
fn main() { | ||
let v1 = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
[ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
], | ||
"FFF", /* item F comment */ | ||
]; | ||
} |
This file contains hidden or 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,165 @@ | ||
// Basic tests (using vectors) - list multiline post-comment is indented on its own | ||
fn main() { | ||
let v = [ | ||
"A", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
]; | ||
} | ||
|
||
fn main() { | ||
let v = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
"FFF", /* item F comment */ | ||
]; | ||
} | ||
|
||
// Tests for Struct | ||
pub(crate) struct ListFormatting<'a> { | ||
tactic: DefinitiveListTactic, | ||
separator: &'a str, /* Comment */ | ||
trailing_separator: SeparatorTactic, /* Comment */ | ||
separator_place: SeparatorPlace, // Comment 1 | ||
// Comment 2 | ||
shape: Shape, /* Non-expressions, e.g., items, will have a new line at the end of the list. | ||
* Important for comment styles. */ | ||
ends_with_newline: bool, // Remove newlines between list elements for expressions. | ||
preserve_newline: bool, // Nested import lists get some special handling for the "Mixed" list type | ||
nested: bool, | ||
// Whether comments should be visually aligned. | ||
align_comments: bool, /* comment */ | ||
config: &'a Config, | ||
} | ||
|
||
fn main() { | ||
l = ListItem { | ||
pre_comment, /* Comment */ | ||
pre_comment_style, /* Multiline comment | ||
* Line 2 */ | ||
/* New line comment */ | ||
item: if self.inner.peek().is_none() && self.leave_last { | ||
/* Comment */ | ||
None | ||
} else { | ||
(self.get_item_string)(&item) | ||
}, | ||
post_comment, /* Comment */ | ||
new_lines, /* Comment */ | ||
} | ||
} | ||
|
||
// Test for Function parameters | ||
pub(crate) fn new(shape: Shape, config: &'a Config) -> Self { | ||
ListFormatting { | ||
tactic: DefinitiveListTactic::Vertical, /* Comment */ | ||
separator: ",", /* comment */ | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, should these comments be aligned? |
||
trailing_separator: SeparatorTactic::Never, /* Multiline comment | ||
* second comment line */ | ||
separator_place: SeparatorPlace::Back, // A longggggggggggggggggggggggggggggggggggggggggggggggggggg comment | ||
shape, | ||
/* New line comment */ | ||
ends_with_newline: true, /* Comment */ | ||
preserve_newline: false, /* Comment */ | ||
nested: false, /* Comment */ | ||
align_comments: true, /* Another Multiline comment | ||
* second comment line */ | ||
config, /* Last comment */ | ||
} | ||
} | ||
|
||
// Test for `where` | ||
impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3> | ||
where | ||
I: Iterator<Item = T>, /* Comment */ | ||
F111111111: Fn(&T) -> BytePos, /* Comment */ | ||
F2222222: Fn(&T) -> BytePos, /* Multiline comment | ||
* Line 2 */ | ||
F3: Fn(&T) -> Option<String>, /* Comment */ | ||
{ | ||
} | ||
|
||
// Test for some types of lists | ||
pub(crate) fn itemize_list<'a, T, I, F1, F2, F3>( | ||
snippet_provider: &'a SnippetProvider, /* Comment */ | ||
inner: I, /* Comment */ | ||
terminator: &'a str, /* Multiline comment | ||
* Line 2 */ | ||
separator: &'a str, /* Comment */ | ||
get_lo: F1, /* Comment */ | ||
get_hi: F2, | ||
get_item_string: F3, /* Comment */ | ||
prev_span_end: BytePos, /* Multiline comment | ||
* Line 2 */ | ||
next_span_start: BytePos, /* Comment */ | ||
leave_last: bool, | ||
) -> ListItems<'a, I, F1, F2, F3> | ||
where | ||
I: Iterator<Item = T>, /* Comment */ | ||
F111111111: Fn(&T) -> BytePos, /* Multiline comment | ||
* Line 2 */ | ||
F2222222: Fn(&T) -> BytePos, | ||
F3: Fn(&T) -> Option<String>, /* Comment */ | ||
{ | ||
ListItems { | ||
/* Comment to ListItems */ | ||
snippet_provider, /* Multiline comment | ||
* Line 2 */ | ||
inner: inner.peekable(), /* Another multiline comment | ||
* another Line 2 */ | ||
get_lo, /* Comment */ | ||
get_hi, | ||
get_item_string, | ||
prev_span_end, /* Comment */ | ||
next_span_start, /* Comment */ | ||
terminator, | ||
separator, /* Yet another multiline comment | ||
* yet another Line 2 */ | ||
leave_last, /* Comment */ | ||
} | ||
} | ||
|
||
// Tests when comment in the same line of the item will exceed line width | ||
fn main() { | ||
let v = [ | ||
"A-Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item A comment */ | ||
"BBB", /* item B Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D-Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"EEEEE", /* item E comment */ | ||
]; | ||
} | ||
|
||
// Test for nested items | ||
fn main() { | ||
let v1 = [ | ||
"GG", /* item G comment line 1 | ||
* item G comment line 2 */ | ||
"AAAAA", /* item A comment */ | ||
[ | ||
"BBB", /* item B comment */ | ||
"CCCCCC", /* item C comment line 1 | ||
* item C comment line 2 */ | ||
"D", /* item D comment line 1 | ||
* item D comment line 2 */ | ||
"E", /* item E comment */ | ||
], | ||
"FFF", /* item F comment */ | ||
]; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should these comments be aligned?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for the alignment of the one line comments is backward compatibility - see this #4546 comment. The workaround is actually applicable only to one line comments. However, assuming that one line comments are the common case, it should be applicable for most of the cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link to the previous discussion!