-
Notifications
You must be signed in to change notification settings - Fork 898
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
fix #6164: Reduce format failure for non default imports_granularity
#6165
base: master
Are you sure you want to change the base?
Changes from 3 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 |
---|---|---|
|
@@ -286,10 +286,21 @@ impl Shape { | |
.ok_or_else(|| self.exceeds_max_width_error(span)) | ||
} | ||
|
||
pub(crate) fn add_width(&self, width: usize) -> Shape { | ||
Shape { | ||
width: self.width + width, | ||
..*self | ||
} | ||
} | ||
Comment on lines
+289
to
+294
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. Can you explain a little more why we needed to implement an 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. Consider this case:
Look at the
Let's trace the behavior of the format above.
Alternative options:
We can't do that because it produces
It's not simple compared to adding So, I added |
||
|
||
pub(crate) fn offset_left_opt(&self, delta: usize) -> Option<Shape> { | ||
self.add_offset(delta).sub_width_opt(delta) | ||
} | ||
|
||
pub(crate) fn offset_left_maybe_overflow(&self, width: usize) -> Shape { | ||
self.add_offset(width).saturating_sub_width(width) | ||
} | ||
Comment on lines
+300
to
+302
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. Similarly, can you explain what 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. Similar. There are the cases that we need to allow overflow temporarily. We can proceed |
||
|
||
pub(crate) fn used_width(&self) -> usize { | ||
self.indent.block_indent + self.offset | ||
} | ||
|
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.
imho: It would be helpful to add a comment explaining why
reserved_room_for_brace
is calculated?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.
Added. Thanks!