-
Notifications
You must be signed in to change notification settings - Fork 926
Pick up comments between visibility modifier and item name #4239
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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
src/formatting/items.rs
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tip! Updated to use combine_strs_with_missing_comments
.
…#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
* 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
Backported in #4564 |
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