-
Notifications
You must be signed in to change notification settings - Fork 892
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
rust-lang/style-team#189: rhs-should-use-indent-of-last-line-of-lhs #6305
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,6 +278,13 @@ impl Shape { | |
offset_indent.to_string_inner(config, 0) | ||
} | ||
|
||
/// similar to to_string_with_newline, except the result does not start with a new line | ||
pub(crate) fn to_string(&self, config: &Config) -> Cow<'static, str> { | ||
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. Probably worth adding a doc comment so that we know that this function gives us a single line of indentation. |
||
let mut offset_indent = self.indent; | ||
offset_indent.alignment = self.offset; | ||
offset_indent.to_string_inner(config, 1) | ||
} | ||
|
||
/// Creates a `Shape` with a virtually infinite width. | ||
pub(crate) fn infinite_width(&self) -> Shape { | ||
Shape { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// rustfmt-style_edition: 2024 | ||
|
||
impl SomeType { | ||
fn method(&mut self) { | ||
self.array[array_index as usize] | ||
.as_mut() | ||
.expect("thing must exist") | ||
.extra_info = Some(ExtraInfo { | ||
parent, | ||
count: count as u16, | ||
children: children.into_boxed_slice(), | ||
}); | ||
} | ||
} | ||
|
||
impl SomeType { | ||
fn method(&mut self) { | ||
self.array[array_index as usize] | ||
.as_mut() | ||
.expect("thing must exist") | ||
.extra_info = | ||
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long; | ||
} | ||
} |
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. There are a few other test cases that I think we should add: impl SomeType {
fn method(&mut self) {
self.array[array_index as usize]
.as_mut()
.expect("thing must exist")
.extra_info = Some(ExtraInfo {
parent,
count: count as u16,
children: children.into_boxed_slice(),
}) + Some(ExtraInfo {
parent,
count: count as u16,
children: children.into_boxed_slice(),
});
}
}
impl SomeType {
fn method(&mut self) {
self.array[array_index as usize]
.as_mut()
.expect("thing must exist")
.extra_info =
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long
.as_mut()
.another_call()
.get_extra_info();
}
}
impl SomeType {
fn method(&mut self) {
self.array[array_index as usize]
.as_mut()
.expect("thing must exist")
.extra_info =
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long
.as_mut()
.another_call()
.get_extra_info() + Some(ExtraInfo {
parent,
count: count as u16,
children: children.into_boxed_slice(),
});
}
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// rustfmt-style_edition: 2024 | ||
|
||
impl SomeType { | ||
fn method(&mut self) { | ||
self.array[array_index as usize] | ||
.as_mut() | ||
.expect("thing must exist") | ||
.extra_info = Some(ExtraInfo { | ||
parent, | ||
count: count as u16, | ||
children: children.into_boxed_slice(), | ||
}); | ||
} | ||
} | ||
|
||
impl SomeType { | ||
fn method(&mut self) { | ||
self.array[array_index as usize] | ||
.as_mut() | ||
.expect("thing must exist") | ||
.extra_info = | ||
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long; | ||
} | ||
} |
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.
Can you explain the call to
.saturating_sub_width(tab_spaces)
. I'm not sure if that's necessary.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.
Without saturating_sub_width,
is formatted to
and throws
rather than
I think the remaining width is not accounted for properly if I only use block_indent
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.
Could you explain why we're using
tab_spaces
? What happens if we don't use.saturating_sub_width(tab_spaces)
, but the rhs was even longer? Does it wrap correctly then?Part of me wonders if the
shape
is off to begin with.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 shape that was used before adding extra block_indent is
and the new shape with block_indent but without saturating_sub_width is
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 new shape is also the shape of the last line of lhs
has 12 spaces before
.extra_info
and.extra_info = long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
is 89 chars. So the remaining width shouldn't be 91, but 87i.e. when indent was 8 spaces, width = 91, max width = 100, so
width = max - indent - 1
when indent is 12, width = 100 - 12 - 1 =87
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.
@ytmimi I think the above should answer your last question in this PR. Can you take a look?
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 detailed explanation. I didn't have time to revisit this PR over the weekend, but I plan on giving this another look later this week