mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 20:46:48 +00:00
Merge pull request #1620 from topecongiro/rfc-if
Use correct line budget when using Rfc control style
This commit is contained in:
commit
0480f7e105
28
src/expr.rs
28
src/expr.rs
@ -326,23 +326,29 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
|
||||
|
||||
// Re-evaluate the rhs because we have more space now:
|
||||
let infix = infix.trim_right();
|
||||
let lhs_budget = try_opt!(context
|
||||
.config
|
||||
.max_width()
|
||||
.checked_sub(shape.used_width() + prefix.len() + infix.len()));
|
||||
let rhs_shape = match context.config.control_style() {
|
||||
Style::Default => {
|
||||
try_opt!(shape.sub_width(suffix.len() + prefix.len())).visual_indent(prefix.len())
|
||||
}
|
||||
Style::Rfc => try_opt!(shape.block_left(context.config.tab_spaces())),
|
||||
Style::Rfc => {
|
||||
shape
|
||||
.block_indent(context.config.tab_spaces())
|
||||
.with_max_width(context.config)
|
||||
}
|
||||
};
|
||||
|
||||
let rhs_result = try_opt!(rhs.rewrite(context, rhs_shape));
|
||||
let lhs_result = try_opt!(lhs.rewrite(context,
|
||||
Shape {
|
||||
width: lhs_budget,
|
||||
..shape
|
||||
}));
|
||||
let lhs_shape = match context.config.control_style() {
|
||||
Style::Default => {
|
||||
let lhs_overhead = shape.used_width() + prefix.len() + infix.len();
|
||||
Shape {
|
||||
width: try_opt!(context.config.max_width().checked_sub(lhs_overhead)),
|
||||
..shape
|
||||
}
|
||||
}
|
||||
Style::Rfc => try_opt!(shape.sub_width(prefix.len() + infix.len())),
|
||||
};
|
||||
let lhs_result = try_opt!(lhs.rewrite(context, lhs_shape));
|
||||
Some(format!("{}{}{}\n{}{}{}",
|
||||
prefix,
|
||||
lhs_result,
|
||||
@ -909,7 +915,7 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||
Some(cond) => {
|
||||
let mut cond_shape = match context.config.control_style() {
|
||||
Style::Default => try_opt!(constr_shape.shrink_left(add_offset)),
|
||||
Style::Rfc => constr_shape,
|
||||
Style::Rfc => try_opt!(constr_shape.sub_width(add_offset)),
|
||||
};
|
||||
if context.config.control_brace_style() != ControlBraceStyle::AlwaysNextLine {
|
||||
// 2 = " {".len()
|
||||
|
23
tests/target/configs-control_style-rfc.rs
Normal file
23
tests/target/configs-control_style-rfc.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// rustfmt-control_style: Rfc
|
||||
|
||||
// #1618
|
||||
fn main() {
|
||||
loop {
|
||||
if foo {
|
||||
if ((right_paddle_speed < 0.) &&
|
||||
(right_paddle.position().y - paddle_size.y / 2. > 5.)) ||
|
||||
((right_paddle_speed > 0.) &&
|
||||
(right_paddle.position().y + paddle_size.y / 2. < game_height as f32 - 5.))
|
||||
{
|
||||
foo
|
||||
}
|
||||
if ai_timer.elapsed_time().as_microseconds() > ai_time.as_microseconds() {
|
||||
if ball.position().y + ball_radius >
|
||||
right_paddle.position().y + paddle_size.y / 2.
|
||||
{
|
||||
foo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user