mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 04:26:48 +00:00
Use correct indentaion for vec! with semicolon
This commit is contained in:
parent
c5538d2a58
commit
4a5871eccc
@ -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) => {
|
||||
|
@ -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
|
||||
|
3
tests/source/issue-1693.rs
Normal file
3
tests/source/issue-1693.rs
Normal 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];
|
||||
}
|
10
tests/target/issue-1693.rs
Normal file
10
tests/target/issue-1693.rs
Normal 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
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue
Block a user