From 740d71794f50365d4a2476125fcae4abe8a5ee4a Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Wed, 11 Mar 2020 11:54:40 -0700 Subject: [PATCH 1/2] tests for 4079 --- rustfmt-core/rustfmt-lib/tests/source/issue-4079.rs | 8 ++++++++ rustfmt-core/rustfmt-lib/tests/target/issue-4079.rs | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rustfmt-core/rustfmt-lib/tests/source/issue-4079.rs create mode 100644 rustfmt-core/rustfmt-lib/tests/target/issue-4079.rs diff --git a/rustfmt-core/rustfmt-lib/tests/source/issue-4079.rs b/rustfmt-core/rustfmt-lib/tests/source/issue-4079.rs new file mode 100644 index 00000000000..eb1ce5ed2a5 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/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/rustfmt-core/rustfmt-lib/tests/target/issue-4079.rs b/rustfmt-core/rustfmt-lib/tests/target/issue-4079.rs new file mode 100644 index 00000000000..1871c5b8a13 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/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 */ From 9914e490ab8b9c7372ff53b8f8889debb0ce8a64 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Wed, 11 Mar 2020 11:54:49 -0700 Subject: [PATCH 2/2] fix 4079 --- rustfmt-core/rustfmt-lib/src/comment.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rustfmt-core/rustfmt-lib/src/comment.rs b/rustfmt-core/rustfmt-lib/src/comment.rs index 148bdf9670e..f55fd0e3596 100644 --- a/rustfmt-core/rustfmt-lib/src/comment.rs +++ b/rustfmt-core/rustfmt-lib/src/comment.rs @@ -528,7 +528,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), @@ -539,14 +538,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, },