Skip to content

Commit

Permalink
Update per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhuichen committed Sep 4, 2024
1 parent 89f1e2b commit 24509fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,21 +2124,21 @@ pub(crate) fn rewrite_assign_rhs_expr<R: Rewrite>(
rhs_kind: &RhsAssignKind<'_>,
rhs_tactics: RhsTactics,
) -> RewriteResult {
let get_lhs_last_line_shape = || {
let last_line = lhs.rsplitn(2, "\n").next().unwrap_or_default();
let get_rhs_shape = || {
let last_line = lhs.lines().last().unwrap_or_default();
let tab_spaces = context.config.tab_spaces();
let new_shape = shape
.block_indent(tab_spaces)
.saturating_sub_width(tab_spaces);
let extra_indent_string = new_shape.to_string(&context.config).to_string();
if last_line.starts_with(&extra_indent_string) {
let extra_indent_string = new_shape.to_string(&context.config);
if last_line.starts_with(extra_indent_string.as_ref()) {
new_shape
} else {
shape
}
};
let shape = if context.config.style_edition() >= StyleEdition::Edition2024 {
get_lhs_last_line_shape()
get_rhs_shape()
} else {
shape
};
Expand Down
1 change: 1 addition & 0 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ 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> {
let mut offset_indent = self.indent;
offset_indent.alignment = self.offset;
Expand Down

0 comments on commit 24509fe

Please sign in to comment.