Skip to content

Issue 4079 #4080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions rustfmt-core/rustfmt-lib/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this nagging suspicion that the offset calc here was used to handle some edge case, though for the life of me I can't think of what that may be nor have I been able to come up with any kind of input that breaks because of this change 🤷‍♂️

As such I think this is probably a good fix, though I wouldn't be completely shocked to see an issue reported at some point in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agreed that there's some risk here to extant code that lacks corresponding tests. I think this logic may have had to do with some confusion in the code about whether * or ** was the right line continuation on doc block comments.

I looked around for C-style comments in a bunch of rust code. I found very little, but didn't see issues with the code I did find.


let mut cr = CommentRewrite {
result: String::with_capacity(orig.len() * 2),
Expand All @@ -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,
},
Expand Down
8 changes: 8 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/source/issue-4079.rs
Original file line number Diff line number Diff line change
@@ -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 */
11 changes: 11 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/issue-4079.rs
Original file line number Diff line number Diff line change
@@ -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 */