Skip to content

Commit c36a223

Browse files
committed
fix attempt
Made this first fix attempt with the hint at [1] [1] rust-lang#5662 (comment)
1 parent ac85c54 commit c36a223

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/items.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,24 @@ impl<'a> FmtVisitor<'a> {
649649

650650
// If one of the variants use multiple lines, use multi-lined formatting for all variants.
651651
let has_multiline_variant = items.iter().any(|item| item.inner_as_ref().contains('\n'));
652-
let has_single_line_variant = items.iter().any(|item| !item.inner_as_ref().contains('\n'));
652+
let has_single_line_variant = items.iter().any(|item| {
653+
let variant_str = item.inner_as_ref();
654+
let mut first_line_is_read = false;
655+
for line in variant_str.split('\n') {
656+
if first_line_is_read {
657+
return false;
658+
}
659+
660+
// skip rustdoc comments and macro attributes
661+
if line.starts_with("///") || line.starts_with("#") {
662+
continue;
663+
} else {
664+
first_line_is_read = true;
665+
}
666+
}
667+
668+
true
669+
});
653670
dbg!(has_multiline_variant);
654671
dbg!(has_single_line_variant);
655672
dbg!(&items);

0 commit comments

Comments
 (0)