Pick up comments between visibility modifier and item name#4239
Merged
Conversation
I don't think this hurts to fix. rust-lang#2781, which surfaced this issue, has a number of comments relating to similar but slightly different issues (i.e. dropped comments in other places). I can mark rust-lang#2781 as closed and then will open new issues for the comments that are not already resolved or tracked. Closes rust-lang#2781
Comment on lines
+2994
to
+3021
| let mut result = String::with_capacity(128); | ||
| let shape = Shape::indented(offset, context.config); | ||
|
|
||
| result.push_str(&format_visibility(context, vis)); | ||
|
|
||
| // Check for a missing comment between the visibility and the item name. | ||
| let after_vis = vis.span.hi(); | ||
| if let Some(before_item_name) = context | ||
| .snippet_provider | ||
| .opt_span_before(mk_sp(vis.span().lo(), ident.span.hi()), item_name.trim()) | ||
| { | ||
| if let Some(cmt) = | ||
| rewrite_missing_comment(mk_sp(after_vis, before_item_name), shape, context) | ||
| { | ||
| result.push_str(&cmt); | ||
| let need_newline = last_line_contains_single_line_comment(&result); | ||
| if need_newline { | ||
| result.push_str(&offset.to_string_with_newline(context.config)); | ||
| } else if cmt.len() > 0 { | ||
| result.push(' '); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| result.push_str(item_name); | ||
| result.push_str(&rewrite_ident(context, ident)); | ||
|
|
||
| result |
Member
There was a problem hiding this comment.
Did you see if using combine_strs_with_missing_comments would be viable? Haven't had a chance to look at this too closely yet, but most cases of comments getting dropped between strings combined with format! can be resolved by using combine_strs_with_missing_comments
Contributor
Author
There was a problem hiding this comment.
Nice tip! Updated to use combine_strs_with_missing_comments.
topecongiro
approved these changes
Jun 7, 2020
calebcartwright
pushed a commit
to calebcartwright/rustfmt
that referenced
this pull request
Nov 29, 2020
…#4239) * Pick up comments between visibility modifier and item name I don't think this hurts to fix. rust-lang#2781, which surfaced this issue, has a number of comments relating to similar but slightly different issues (i.e. dropped comments in other places). I can mark rust-lang#2781 as closed and then will open new issues for the comments that are not already resolved or tracked. Closes rust-lang#2781 * fixup! Pick up comments between visibility modifier and item name * fixup! Pick up comments between visibility modifier and item name
calebcartwright
pushed a commit
that referenced
this pull request
Nov 29, 2020
* Pick up comments between visibility modifier and item name I don't think this hurts to fix. #2781, which surfaced this issue, has a number of comments relating to similar but slightly different issues (i.e. dropped comments in other places). I can mark #2781 as closed and then will open new issues for the comments that are not already resolved or tracked. Closes #2781 * fixup! Pick up comments between visibility modifier and item name * fixup! Pick up comments between visibility modifier and item name
Contributor
|
Backported in #4564 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I don't think this hurts to fix. #2781, which surfaced this issue, has
a number of comments relating to similar but slightly different issues
(i.e. dropped comments in other places). I can mark #2781 as closed and
then will open new issues for the comments that are not already resolved
or tracked.
Closes #2781