mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Merge pull request #2160 from topecongiro/issue-1809
Force vertical layout for all variants if one of then use multiple lines
This commit is contained in:
commit
abe6eec910
@ -45,7 +45,9 @@ enum Operation {
|
|||||||
/// Print detailed configuration help.
|
/// Print detailed configuration help.
|
||||||
ConfigHelp,
|
ConfigHelp,
|
||||||
/// Output default config to a file, or stdout if None
|
/// Output default config to a file, or stdout if None
|
||||||
ConfigOutputDefault { path: Option<String> },
|
ConfigOutputDefault {
|
||||||
|
path: Option<String>,
|
||||||
|
},
|
||||||
/// No file specified, read from stdin
|
/// No file specified, read from stdin
|
||||||
Stdin {
|
Stdin {
|
||||||
input: String,
|
input: String,
|
||||||
|
45
src/items.rs
45
src/items.rs
@ -484,21 +484,30 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
let indentation = self.block_indent.to_string(self.config);
|
let indentation = self.block_indent.to_string(self.config);
|
||||||
result.push_str(&indentation);
|
result.push_str(&indentation);
|
||||||
|
|
||||||
let items = itemize_list(
|
let itemize_list_with = |one_line_width: usize| {
|
||||||
self.codemap,
|
itemize_list(
|
||||||
enum_def.variants.iter(),
|
self.codemap,
|
||||||
"}",
|
enum_def.variants.iter(),
|
||||||
|f| if !f.node.attrs.is_empty() {
|
"}",
|
||||||
f.node.attrs[0].span.lo()
|
|f| if !f.node.attrs.is_empty() {
|
||||||
} else {
|
f.node.attrs[0].span.lo()
|
||||||
f.span.lo()
|
} else {
|
||||||
},
|
f.span.lo()
|
||||||
|f| f.span.hi(),
|
},
|
||||||
|f| self.format_variant(f),
|
|f| f.span.hi(),
|
||||||
body_lo,
|
|f| self.format_variant(f, one_line_width),
|
||||||
body_hi,
|
body_lo,
|
||||||
false,
|
body_hi,
|
||||||
);
|
false,
|
||||||
|
).collect()
|
||||||
|
};
|
||||||
|
let mut items: Vec<_> = itemize_list_with(self.config.struct_variant_width());
|
||||||
|
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
|
||||||
|
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains("\n"));
|
||||||
|
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains("\n"));
|
||||||
|
if has_multiline_variant && has_single_line_variant {
|
||||||
|
items = itemize_list_with(0);
|
||||||
|
}
|
||||||
|
|
||||||
let shape = self.shape().sub_width(2).unwrap();
|
let shape = self.shape().sub_width(2).unwrap();
|
||||||
let fmt = ListFormatting {
|
let fmt = ListFormatting {
|
||||||
@ -512,14 +521,14 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
config: self.config,
|
config: self.config,
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = write_list(&items.collect::<Vec<_>>(), &fmt)?;
|
let list = write_list(&items, &fmt)?;
|
||||||
result.push_str(&list);
|
result.push_str(&list);
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variant of an enum.
|
// Variant of an enum.
|
||||||
fn format_variant(&self, field: &ast::Variant) -> Option<String> {
|
fn format_variant(&self, field: &ast::Variant, one_line_width: usize) -> Option<String> {
|
||||||
if contains_skip(&field.node.attrs) {
|
if contains_skip(&field.node.attrs) {
|
||||||
let lo = field.node.attrs[0].span.lo();
|
let lo = field.node.attrs[0].span.lo();
|
||||||
let span = mk_sp(lo, field.span.hi());
|
let span = mk_sp(lo, field.span.hi());
|
||||||
@ -544,7 +553,7 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
&context,
|
&context,
|
||||||
&StructParts::from_variant(field),
|
&StructParts::from_variant(field),
|
||||||
indent,
|
indent,
|
||||||
Some(self.config.struct_variant_width()),
|
Some(one_line_width),
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
|
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
|
||||||
|
@ -146,3 +146,22 @@ pub enum ForegroundColor {
|
|||||||
pub enum E<'a> {
|
pub enum E<'a> {
|
||||||
V ( < std::slice::Iter<'a, Xxxxxxxxxxxxxx> as Iterator> :: Item ) ,
|
V ( < std::slice::Iter<'a, Xxxxxxxxxxxxxx> as Iterator> :: Item ) ,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #1809
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
@ -44,7 +44,9 @@ enum StructLikeVariants {
|
|||||||
// Pre-comment
|
// Pre-comment
|
||||||
#[Attr50] y: SomeType, // Aanother Comment
|
#[Attr50] y: SomeType, // Aanother Comment
|
||||||
},
|
},
|
||||||
SL { a: A },
|
SL {
|
||||||
|
a: A,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enum X {
|
enum X {
|
||||||
@ -65,7 +67,10 @@ pub enum EnumWithAttributes {
|
|||||||
SkippedItem(String,String,), // Post-comment
|
SkippedItem(String,String,), // Post-comment
|
||||||
#[another_attr]
|
#[another_attr]
|
||||||
#[attr2]
|
#[attr2]
|
||||||
ItemStruct { x: usize, y: usize }, /* Comment AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */
|
ItemStruct {
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
}, /* Comment AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */
|
||||||
// And another
|
// And another
|
||||||
ForcedPreflight, /* AAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
ForcedPreflight, /* AAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */
|
* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA */
|
||||||
@ -183,3 +188,30 @@ pub enum ForegroundColor {
|
|||||||
pub enum E<'a> {
|
pub enum E<'a> {
|
||||||
V(<std::slice::Iter<'a, Xxxxxxxxxxxxxx> as Iterator>::Item),
|
V(<std::slice::Iter<'a, Xxxxxxxxxxxxxx> as Iterator>::Item),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #1809
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user