-
Notifications
You must be signed in to change notification settings - Fork 902
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
Open
johnhuichen
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
johnhuichen:rust-lang/style-team#189-rhs-should-use-indent-of-last-line-of-lhs
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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,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(),
});
}
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.
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.
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