Skip to content

Fix #5533: Prefer light_rewrite_comment if it is not a doccomment #5536

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 4 commits into from
Sep 11, 2023
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
6 changes: 5 additions & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ fn identify_comment(
trim_left_preserve_layout(first_group, shape.indent, config)?
} else if !config.normalize_comments()
&& !config.wrap_comments()
&& !config.format_code_in_doc_comments()
&& !(
// `format_code_in_doc_comments` should only take effect on doc comments,
// so we only consider it when this comment block is a doc comment block.
is_doc_comment && config.format_code_in_doc_comments()
)
{
light_rewrite_comment(first_group, shape.indent, config, is_doc_comment)
} else {
Expand Down
14 changes: 14 additions & 0 deletions tests/target/issue-5568.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rustfmt-max_width: 119
// rustfmt-format_code_in_doc_comments: true

mod libs {
fn mrbgems_sources() {
[
"mrbgems/mruby-compiler/core/codegen.c", // Ruby parser and bytecode generation
"mrbgems/mruby-compiler/core/y.tab.c", // Ruby parser and bytecode generation
"mrbgems/mruby-metaprog/src/metaprog.c", // APIs on Kernel and Module for accessing classes and variables
"mrbgems/mruby-method/src/method.c", // `Method`, `UnboundMethod`, and method APIs on Kernel and Module
"mrbgems/mruby-pack/src/pack.c", // Array#pack and String#unpack
]
}
}
6 changes: 6 additions & 0 deletions tests/target/issue_5533.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-format_code_in_doc_comments: true

struct TestStruct {
position_currency: String, // Currency for position of this contract. If not null, 1 contract = 1 positionCurrency.
pu: Option<i64>, // Previous event update sequense ("u" of previous message), -1 also means None
}
6 changes: 6 additions & 0 deletions tests/target/issue_5907.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-format_code_in_doc_comments: true

// ```
// [
// ]
// ```