Skip to content
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

Try to solve issue 3417. #3535

Merged
merged 7 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ fn main() {

## `format_doc_comments`

Format doc comments.
Format code snippet in doc comments.

- **Default value**: `false`
- **Possible values**: `true`, `false`
Expand Down
13 changes: 10 additions & 3 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to write this if block a better way, please give me suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I wonder how to select multiply lines in the commit view. please give me suggestion.

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)
}
}
};
Expand Down
1 change: 1 addition & 0 deletions tests/source/issue-2520.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

//! ```rust
//! println!( "hello, world" );
Expand Down
1 change: 1 addition & 0 deletions tests/source/issue-2523.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

// Do not unindent macro calls in comment with unformattable syntax.
//! ```rust
Expand Down
1 change: 1 addition & 0 deletions tests/source/issue-3055/original.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
1 change: 1 addition & 0 deletions tests/source/itemized-blocks/no_wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

//! This is a list:
//! * Outer
Expand Down
1 change: 1 addition & 0 deletions tests/source/itemized-blocks/wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
// rustfmt-max_width: 50

//! This is a list:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-normalize_doc_attributes: true

/// Foo
///
/// # Example
/// ```
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
/// # #![cfg_attr(not(dox), no_std)]
/// fn foo() { }
/// ```
///
fn foo() {}

#[doc = "Bar documents"]
fn bar() {}
16 changes: 16 additions & 0 deletions tests/source/wrap_comments_should_not_imply_format_doc_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// rustfmt-wrap_comments: true

/// Foo
///
/// # Example
/// ```
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
/// # #![cfg_attr(not(dox), no_std)]
/// fn foo() { }
/// ```
///
fn foo() {}

/// A long commment for wrapping
/// This is a long long long long long long long long long long long long long long long long long long long long sentence.
fn bar() {}
1 change: 1 addition & 0 deletions tests/target/issue-2520.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

//! ```rust
//! println!("hello, world");
Expand Down
1 change: 1 addition & 0 deletions tests/target/issue-2523.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

// Do not unindent macro calls in comment with unformattable syntax.
//! ```rust
Expand Down
1 change: 1 addition & 0 deletions tests/target/issue-3055/original.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/target/itemized-blocks/no_wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-format_doc_comments: true

//! This is a list:
//! * Outer
Expand Down
1 change: 1 addition & 0 deletions tests/target/itemized-blocks/wrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// rustfmt-wrap_comments: true
// rustfmt-format_doc_comments: true
// rustfmt-max_width: 50

//! This is a list:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-normalize_doc_attributes: true

/// Foo
///
/// # Example
/// ```
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
/// # #![cfg_attr(not(dox), no_std)]
/// fn foo() { }
/// ```
///
fn foo() {}

///Bar documents
fn bar() {}
16 changes: 16 additions & 0 deletions tests/target/wrap_comments_should_not_imply_format_doc_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// rustfmt-wrap_comments: true

/// Foo
///
/// # Example
/// ```
/// # #![cfg_attr(not(dox), feature(cfg_target_feature, target_feature, stdsimd))]
/// # #![cfg_attr(not(dox), no_std)]
/// fn foo() { }
/// ```
fn foo() {}

/// A long commment for wrapping
/// This is a long long long long long long long long long long long long long
/// long long long long long long long sentence.
fn bar() {}