Skip to content

Commit b57ded9

Browse files
committed
to use find_last_uncommented
to remove has_rhs_comment
1 parent a3867a5 commit b57ded9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/expr.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,6 @@ pub(crate) fn rewrite_assign_rhs_expr<R: Rewrite>(
18871887
ex: &R,
18881888
shape: Shape,
18891889
rhs_tactics: RhsTactics,
1890-
has_rhs_comment: bool,
18911890
) -> Option<String> {
18921891
let last_line_width = last_line_width(&lhs).saturating_sub(if lhs.contains('\n') {
18931892
shape.indent.width()
@@ -1900,6 +1899,12 @@ pub(crate) fn rewrite_assign_rhs_expr<R: Rewrite>(
19001899
offset: shape.offset + last_line_width + 1,
19011900
..shape
19021901
});
1902+
let has_rhs_comment = if let Some(offset) = lhs.find_last_uncommented("=") {
1903+
lhs.trim_end().len() > offset + 1
1904+
} else {
1905+
false
1906+
};
1907+
19031908
choose_rhs(
19041909
context,
19051910
ex,
@@ -1918,7 +1923,7 @@ pub(crate) fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
19181923
rhs_tactics: RhsTactics,
19191924
) -> Option<String> {
19201925
let lhs = lhs.into();
1921-
let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_tactics, false)?;
1926+
let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_tactics)?;
19221927
Some(lhs + &rhs)
19231928
}
19241929

src/items.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ impl Rewrite for ast::Local {
111111

112112
result.push_str(&infix);
113113

114-
let mut has_comment_between_assign_and_rhs = false;
115114
if let Some(ref ex) = self.init {
116115
let base_span = if let Some(ref ty) = self.ty {
117116
mk_sp(ty.span.hi(), self.span.hi())
@@ -161,7 +160,6 @@ impl Rewrite for ast::Local {
161160
result.push_str(new_indent_str);
162161
result.push_str(comment_after_assign);
163162
result.push_str(new_indent_str);
164-
has_comment_between_assign_and_rhs = true;
165163
}
166164
}
167165

@@ -173,7 +171,6 @@ impl Rewrite for ast::Local {
173171
&**ex,
174172
nested_shape,
175173
RhsTactics::Default,
176-
has_comment_between_assign_and_rhs,
177174
)?;
178175
result = result + &rhs;
179176
}

0 commit comments

Comments
 (0)