Isolate format_doc_comment with normalize_comments and wrap_comments.

This commit is contained in:
xiongmao86 2019-05-02 21:11:13 +08:00
parent a653e30d9f
commit 3300bb22a5
12 changed files with 20 additions and 4 deletions

View File

@ -656,9 +656,16 @@ impl<'a> CommentRewrite<'a> {
_ => {
let mut config = self.fmt.config.clone();
config.set().wrap_comments(false);
match crate::format_code_block(&self.code_block_buffer, &config) {
Some(ref s) => trim_custom_comment_prefix(&s.snippet),
None => trim_custom_comment_prefix(&self.code_block_buffer),
if config.format_doc_comments() {
if let Some(s) =
crate::format_code_block(&self.code_block_buffer, &config)
{
trim_custom_comment_prefix(&s.snippet)
} else {
trim_custom_comment_prefix(&self.code_block_buffer)
}
} else {
trim_custom_comment_prefix(&self.code_block_buffer)
}
}
};

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
//! ```rust
//! println!( "hello, world" );

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
// Do not unindent macro calls in comment with unformattable syntax.
//! ```rust

View File

@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
/// Vestibulum elit nibh, rhoncus non, euismod sit amet, pretium eu, enim. Nunc commodo ultricies dui.
///

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
//! This is a list:
//! * Outer

View File

@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
// rustfmt-max_width: 50
//! This is a list:

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
//! ```rust
//! println!("hello, world");

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
// Do not unindent macro calls in comment with unformattable syntax.
//! ```rust

View File

@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
/// Vestibulum elit nibh, rhoncus non, euismod sit amet, pretium eu, enim. Nunc
/// commodo ultricies dui.

View File

@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true
//! This is a list:
//! * Outer

View File

@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
// rustfmt-max_width: 50
//! This is a list:

View File

@ -8,7 +8,6 @@
/// # #![cfg_attr(not(dox), no_std)]
/// fn foo() { }
/// ```
///
fn foo() {}
/// A long commment for wrapping