Use correct indentaion for vec! with semicolon

This commit is contained in:
topecongiro 2017-06-16 13:57:37 +09:00
parent c5538d2a58
commit 4a5871eccc
4 changed files with 21 additions and 9 deletions

View File

@ -157,9 +157,8 @@ fn format_expr(
ast::ExprKind::Loop(..) |
ast::ExprKind::While(..) |
ast::ExprKind::WhileLet(..) => {
to_control_flow(expr, expr_type).and_then(|control_flow| {
control_flow.rewrite(context, shape)
})
to_control_flow(expr, expr_type)
.and_then(|control_flow| control_flow.rewrite(context, shape))
}
ast::ExprKind::Block(ref block) => block.rewrite(context, shape),
ast::ExprKind::Match(ref cond, ref arms) => {

View File

@ -184,7 +184,7 @@ pub fn rewrite_macro(
)
}
MacroStyle::Brackets => {
let mac_shape = try_opt!(shape.shrink_left(macro_name.len()));
let mac_shape = try_opt!(shape.offset_left(macro_name.len()));
// Handle special case: `vec![expr; expr]`
if vec_with_semi {
let (lbr, rbr) = if context.config.spaces_within_square_brackets() {
@ -194,21 +194,21 @@ pub fn rewrite_macro(
};
// 6 = `vec!` + `; `
let total_overhead = lbr.len() + rbr.len() + 6;
let lhs = try_opt!(expr_vec[0].rewrite(context, mac_shape));
let rhs = try_opt!(expr_vec[1].rewrite(context, mac_shape));
let nested_shape = mac_shape.block_indent(context.config.tab_spaces());
let lhs = try_opt!(expr_vec[0].rewrite(context, nested_shape));
let rhs = try_opt!(expr_vec[1].rewrite(context, nested_shape));
if !lhs.contains('\n') && !rhs.contains('\n') &&
lhs.len() + rhs.len() + total_overhead <= shape.width
{
Some(format!("{}{}{}; {}{}", macro_name, lbr, lhs, rhs, rbr))
} else {
let nested_indent = shape.indent.block_indent(context.config);
Some(format!(
"{}{}\n{}{};\n{}{}\n{}{}",
macro_name,
lbr,
nested_indent.to_string(context.config),
nested_shape.indent.to_string(context.config),
lhs,
nested_indent.to_string(context.config),
nested_shape.indent.to_string(context.config),
rhs,
shape.indent.to_string(context.config),
rbr

View File

@ -0,0 +1,3 @@
fn issue1693() {
let pixel_data = vec![(f16::from_f32(0.82), f16::from_f32(1.78), f16::from_f32(0.21)); 256 * 256];
}

View File

@ -0,0 +1,10 @@
fn issue1693() {
let pixel_data = vec![
(
f16::from_f32(0.82),
f16::from_f32(1.78),
f16::from_f32(0.21)
);
256 * 256
];
}