Skip to content

Commit c0c3b3e

Browse files
committed
Changes per reviewer comments - remove untested handling of assign pre comments
1 parent 3d48d2e commit c0c3b3e

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

src/items.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -112,56 +112,26 @@ impl Rewrite for ast::Local {
112112

113113
result.push_str(&infix);
114114

115-
if let Some((init, _els)) = self.kind.init_else_opt() {
115+
if let Some(expr) = self.kind.init() {
116116
let base_span = if let Some(ref ty) = self.ty {
117117
mk_sp(ty.span.hi(), self.span.hi())
118118
} else {
119119
mk_sp(self.pat.span.hi(), self.span.hi())
120120
};
121121

122-
let offset = context.snippet(base_span).find_uncommented("=")?;
123-
let base_span_lo = base_span.lo();
124-
125-
let assign_lo = base_span_lo + BytePos(offset as u32);
126-
let comment_start_pos = if let Some(ref ty) = self.ty {
127-
ty.span.hi()
128-
} else {
129-
self.pat.span.hi()
130-
};
131-
let comment_before_assign = context.snippet(mk_sp(comment_start_pos, assign_lo)).trim();
132-
133-
let assign_hi = base_span_lo + BytePos((offset + 1) as u32);
134-
let rhs_span_lo = init.span.lo();
135-
let comment_end_pos = if init.attrs.is_empty() {
136-
rhs_span_lo
137-
} else {
138-
let attr_span_lo = init.attrs.first().unwrap().span.lo();
139-
// for the case using block
140-
// ex. let x = { #![my_attr]do_something(); }
141-
if rhs_span_lo < attr_span_lo {
142-
rhs_span_lo
143-
} else {
144-
attr_span_lo
145-
}
146-
};
147-
148-
if !comment_before_assign.is_empty() {
149-
let new_indent_str = &pat_shape
150-
.block_indent(0)
151-
.to_string_with_newline(context.config);
152-
result = format!("{}{}{}", comment_before_assign, new_indent_str, result);
153-
}
122+
let comment_lo = context.snippet_provider.span_after(base_span, "=");
123+
let comment_span = mk_sp(comment_lo, expr.span.lo());
154124

155125
// 1 = trailing semicolon;
156126
let nested_shape = shape.sub_width(1)?;
157127
result = rewrite_assign_rhs_with_comments(
158128
context,
159129
result,
160-
init,
130+
expr,
161131
nested_shape,
162-
&RhsAssignKind::Expr(&init.kind, init.span),
132+
&RhsAssignKind::Expr(&expr.kind, expr.span),
163133
RhsTactics::Default,
164-
mk_sp(assign_hi, comment_end_pos),
134+
comment_span,
165135
true,
166136
)?;
167137
}

0 commit comments

Comments
 (0)