Prefer light_rewrite_comment if it is not a doccomment (#5536)

Fixes 5533, 5568, 5907

Prevent `format_code_in_doc_comments=true` from affecting how non-doc comments are formatted.


---------

Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
This commit is contained in:
pan93412 2023-09-12 02:15:59 +08:00 committed by GitHub
parent 262feb3337
commit 18737ddc72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 1 deletions

View File

@ -365,7 +365,11 @@ fn consume_same_line_comments(
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 {

View File

@ -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
]
}
}

View File

@ -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
}

View File

@ -0,0 +1,6 @@
// rustfmt-format_code_in_doc_comments: true
// ```
// [
// ]
// ```