Merge pull request #1816 from topecongiro/struct-variant-width-0

Force vertical layout when struct_variant_width is 0
This commit is contained in:
Nick Cameron 2017-07-26 11:32:42 +12:00 committed by GitHub
commit 7634bd3be0
2 changed files with 33 additions and 2 deletions

View File

@ -1128,16 +1128,18 @@ pub fn format_struct_struct(
.max_width()
.checked_sub(result.len() + 3 + offset.width())
.unwrap_or(0);
let one_line_budget =
one_line_width.map_or(0, |one_line_width| min(one_line_width, one_line_budget));
let items_str = try_opt!(rewrite_with_alignment(
fields,
context,
Shape::indented(offset, context.config),
mk_sp(body_lo, span.hi),
one_line_width.map_or(0, |one_line_width| min(one_line_width, one_line_budget)),
one_line_budget,
));
if one_line_width.is_some() && !items_str.contains('\n') && !result.contains('\n') {
if !items_str.contains('\n') && !result.contains('\n') && items_str.len() <= one_line_budget {
Some(format!("{} {} }}", result, items_str))
} else {
Some(format!(

View File

@ -0,0 +1,29 @@
// rustfmt-struct_variant_width: 0
// Force vertical layout when struct_variant_width is set to 0.
enum State {
TryRecv {
pos: usize,
lap: u8,
closed_count: usize,
},
Subscribe {
pos: usize,
},
IsReady {
pos: usize,
ready: bool,
},
Unsubscribe {
pos: usize,
lap: u8,
id_woken: usize,
},
FinalTryRecv {
pos: usize,
id_woken: usize,
},
TimedOut,
Disconnected,
}