From 796d6eafa40ae26e245be92c74709151eb343447 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Thu, 11 Jun 2020 23:29:51 -0500 Subject: [PATCH] fix: backport fix for #4079 --- src/comment.rs | 5 ++--- tests/source/issue-4079.rs | 8 ++++++++ tests/target/issue-4079.rs | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/source/issue-4079.rs create mode 100644 tests/target/issue-4079.rs diff --git a/src/comment.rs b/src/comment.rs index 7a0183f59af6..1da62d176817 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -529,7 +529,6 @@ impl<'a> CommentRewrite<'a> { .checked_sub(closer.len() + opener.len()) .unwrap_or(1); let indent_str = shape.indent.to_string_with_newline(config).to_string(); - let fmt_indent = shape.indent + (opener.len() - line_start.len()); let mut cr = CommentRewrite { result: String::with_capacity(orig.len() * 2), @@ -540,14 +539,14 @@ impl<'a> CommentRewrite<'a> { comment_line_separator: format!("{}{}", indent_str, line_start), max_width, indent_str, - fmt_indent, + fmt_indent: shape.indent, fmt: StringFormat { opener: "", closer: "", line_start, line_end: "", - shape: Shape::legacy(max_width, fmt_indent), + shape: Shape::legacy(max_width, shape.indent), trim_end: true, config, }, diff --git a/tests/source/issue-4079.rs b/tests/source/issue-4079.rs new file mode 100644 index 000000000000..eb1ce5ed2a5b --- /dev/null +++ b/tests/source/issue-4079.rs @@ -0,0 +1,8 @@ +// rustfmt-wrap_comments: true + +/*! + * Lorem ipsum dolor sit amet, consectetur adipiscing elit. In lacinia + * ullamcorper lorem, non hendrerit enim convallis ut. Curabitur id sem volutpat + */ + +/*! Lorem ipsum dolor sit amet, consectetur adipiscing elit. In lacinia ullamcorper lorem, non hendrerit enim convallis ut. Curabitur id sem volutpat */ diff --git a/tests/target/issue-4079.rs b/tests/target/issue-4079.rs new file mode 100644 index 000000000000..1871c5b8a133 --- /dev/null +++ b/tests/target/issue-4079.rs @@ -0,0 +1,11 @@ +// rustfmt-wrap_comments: true + +/*! + * Lorem ipsum dolor sit amet, consectetur adipiscing elit. In lacinia + * ullamcorper lorem, non hendrerit enim convallis ut. Curabitur id sem + * volutpat + */ + +/*! Lorem ipsum dolor sit amet, consectetur adipiscing elit. In lacinia + * ullamcorper lorem, non hendrerit enim convallis ut. Curabitur id sem + * volutpat */