diff --git a/src/imports.rs b/src/imports.rs index 4a1370e98cb..a59d7519e2a 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -1110,7 +1110,7 @@ impl Rewrite for UseSegment { use_tree_list, // 1 = "{" and "}" shape - .offset_left(1) + .offset_left_opt(1) .unknown_error()? .saturating_sub_width(1), )? @@ -1160,7 +1160,7 @@ impl Rewrite for UseTree { s.clone() } } else { - let Some(ret) = shape.offset_left(rewritten_segment.len()) else { + let Some(ret) = shape.offset_left_opt(rewritten_segment.len()) else { return Err(RewriteError::ExceedsMaxWidth { configured_width: shape.width, span: span.clone(), @@ -1168,7 +1168,7 @@ impl Rewrite for UseTree { }; // Check that there is a room for the next "{". If not, return an error for // retry with newline. - if ret.offset_left(reserved_room_for_brace).is_none() { + if ret.offset_left_opt(reserved_room_for_brace).is_none() { return Err(RewriteError::ExceedsMaxWidth { configured_width: shape.width, span: span.clone(), @@ -1221,7 +1221,7 @@ impl Rewrite for UseTree { result.push_str("::"); // 2 = "::" shape = shape - .offset_left(2 + segment_str.len()) + .offset_left_opt(2 + segment_str.len()) .max_width_error(shape.width, self.span())?; } } diff --git a/src/shape.rs b/src/shape.rs index 5b2161b4ce8..d753b8e0402 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -293,14 +293,6 @@ impl Shape { } } - pub(crate) fn shrink_left(&self, width: usize) -> Option { - Some(Shape { - width: self.width.checked_sub(width)?, - indent: self.indent + width, - offset: self.offset + width, - }) - } - pub(crate) fn offset_left_opt(&self, delta: usize) -> Option { self.add_offset(delta).sub_width_opt(delta) }