-
Notifications
You must be signed in to change notification settings - Fork 861
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 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 |
---|---|---|
|
@@ -242,6 +242,13 @@ impl Shape { | |
}) | ||
} | ||
|
||
pub(crate) fn add_width(&self, width: usize) -> Shape { | ||
Shape { | ||
width: self.width + width, | ||
..*self | ||
} | ||
} | ||
|
||
pub(crate) fn shrink_left(&self, width: usize) -> Option<Shape> { | ||
Some(Shape { | ||
width: self.width.checked_sub(width)?, | ||
|
@@ -254,6 +261,10 @@ impl Shape { | |
self.add_offset(width).sub_width(width) | ||
} | ||
|
||
pub(crate) fn offset_left_maybe_overflow(&self, width: usize) -> Shape { | ||
self.add_offset(width).saturating_sub_width(width) | ||
} | ||
Comment on lines
+264
to
+266
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.
Can you explain a little more why we needed to implement an
add_width
method on theShape
?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.
Consider this case:
Look at the
UseTree::rewrite()
, especiallyLet's trace the behavior of the format above.
Alternative options:
segment.rewrite(context, shape.infinite_width())?;
at theTIMING1
instead.We can't do that because it produces
UseSegment::rewirte()
that can handle yet another argumentshould_commit_open_brace_even_if_no_width
.It's not simple compared to adding
Shape::add_width()
...So, I added
Shape::add_width()
.