Skip to content

Commit 8e49f20

Browse files
committed
Changes per revierwr comments
1 parent d1da537 commit 8e49f20

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

src/items.rs

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,52 +112,60 @@ impl Rewrite for ast::Local {
112112

113113
result.push_str(&infix);
114114

115-
if context.config.version() == Version::One {
116-
if let Some((init, _els)) = self.kind.init_else_opt() {
117-
// 1 = trailing semicolon;
118-
let nested_shape = shape.sub_width(1)?;
119-
120-
result = rewrite_assign_rhs(
121-
context,
122-
result,
123-
init,
124-
&RhsAssignKind::Expr(&init.kind, init.span),
125-
nested_shape,
126-
)?;
127-
// todo else
128-
}
129-
} else {
130-
// Version:Two+
131-
if let Some(expr) = self.kind.init() {
132-
let base_span = if let Some(ref ty) = self.ty {
133-
mk_sp(ty.span.hi(), self.span.hi())
134-
} else {
135-
mk_sp(self.pat.span.hi(), self.span.hi())
136-
};
137-
138-
let comment_lo = context.snippet_provider.span_after(base_span, "=");
139-
let comment_span = mk_sp(comment_lo, expr.span.lo());
115+
if let Some((init, _els)) = self.kind.init_else_opt() {
116+
let base_span = if let Some(ref ty) = self.ty {
117+
mk_sp(ty.span.hi(), self.span.hi())
118+
} else {
119+
mk_sp(self.pat.span.hi(), self.span.hi())
120+
};
140121

141-
// 1 = trailing semicolon;
142-
let nested_shape = shape.sub_width(1)?;
143-
result = rewrite_assign_rhs_with_comments(
144-
context,
145-
result,
146-
expr,
147-
nested_shape,
148-
&RhsAssignKind::Expr(&expr.kind, expr.span),
149-
RhsTactics::Default,
150-
comment_span,
151-
true,
152-
)?;
153-
}
122+
result = rewrite_initializer_expr(context, init, result, base_span, shape)?;
154123
}
124+
// todo else of kind.init_else_opt
155125

156126
result.push(';');
157127
Some(result)
158128
}
159129
}
160130

131+
fn rewrite_initializer_expr(
132+
context: &RewriteContext<'_>,
133+
init: &ast::Expr,
134+
lhs: String,
135+
base_span: Span,
136+
shape: Shape,
137+
) -> Option<String> {
138+
if context.config.version() == Version::One {
139+
// 1 = trailing semicolon;
140+
let nested_shape = shape.sub_width(1)?;
141+
142+
rewrite_assign_rhs(
143+
context,
144+
lhs,
145+
init,
146+
&RhsAssignKind::Expr(&init.kind, init.span),
147+
nested_shape,
148+
)
149+
} else {
150+
// Version:Two+
151+
let comment_lo = context.snippet_provider.span_after(base_span, "=");
152+
let comment_span = mk_sp(comment_lo, init.span.lo());
153+
154+
// 1 = trailing semicolon;
155+
let nested_shape = shape.sub_width(1)?;
156+
rewrite_assign_rhs_with_comments(
157+
context,
158+
lhs,
159+
init,
160+
nested_shape,
161+
&RhsAssignKind::Expr(&init.kind, init.span),
162+
RhsTactics::Default,
163+
comment_span,
164+
true,
165+
)
166+
}
167+
}
168+
161169
// FIXME convert to using rewrite style rather than visitor
162170
// FIXME format modules in this style
163171
#[allow(dead_code)]

0 commit comments

Comments
 (0)