X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Frustfmt%2Fsrc%2Flists.rs;h=3515dd172510c91e6bc109c7378ab8cccd82f0b2;hb=f6ade7ca36ba326216ea58bc87b42d84711ad6de;hp=d341ec8e6b0e7d15f428cc3e91527635129f9687;hpb=032dfe43605f4324966933078ffe6f717b77c7c8;p=rust.git diff --git a/src/tools/rustfmt/src/lists.rs b/src/tools/rustfmt/src/lists.rs index d341ec8e6b0..3515dd17251 100644 --- a/src/tools/rustfmt/src/lists.rs +++ b/src/tools/rustfmt/src/lists.rs @@ -444,10 +444,15 @@ pub(crate) fn write_list(items: I, formatting: &ListFormatting<'_>) -> Opt let offset = formatting.shape.indent + overhead; let comment_shape = Shape::legacy(width, offset); - // Use block-style only for the last item or multiline comments. - let block_style = !formatting.ends_with_newline && last - || comment.trim().contains('\n') - || comment.trim().len() > width; + let block_style = if !formatting.ends_with_newline && last { + true + } else if starts_with_newline(comment) { + false + } else if comment.trim().contains('\n') || comment.trim().len() > width { + true + } else { + false + }; rewrite_comment( comment.trim_start(),