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

Fix for handling empty code block in doc comment #5601

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/comment.rs
Expand Up @@ -726,7 +726,7 @@ impl<'a> CommentRewrite<'a> {
let code_block = match self.code_block_attr.as_ref().unwrap() {
CodeBlockAttribute::Rust
if self.fmt.config.format_code_in_doc_comments()
&& !self.code_block_buffer.is_empty() =>
&& !self.code_block_buffer.trim().is_empty() =>
{
let mut config = self.fmt.config.clone();
config.set().wrap_comments(false);
Expand Down
51 changes: 51 additions & 0 deletions tests/source/issue-5234.rs
@@ -0,0 +1,51 @@
// rustfmt-format_code_in_doc_comments: true

/// ```
/// ```
fn foo() {}

/// ```
///Something
/// ```
fn foo() {}

/// ```
///
/// ```
fn foo() {}


/// /// ```
fn foo() {}

/// /// ```
/// ```
///
/// ```
/// ```
fn foo() {}

fn foo() {
/// ```
///
/// ```
struct bar {}
}

/// ```
/// fn com(){
/// let i = 5;
///
/// let j = 6;
/// }
/// ```
fn foo() {}

fn foo() {
/// ```
///fn com(){
///let i = 5;
///}
/// ```
struct bar {}
}
47 changes: 47 additions & 0 deletions tests/target/issue-5234.rs
@@ -0,0 +1,47 @@
// rustfmt-format_code_in_doc_comments: true

/// ```
/// ```
fn foo() {}

/// ```
/// Something
/// ```
fn foo() {}

/// ```
/// ```
fn foo() {}

/// /// ```
fn foo() {}

/// /// ```
/// ```
/// ```
/// ```
fn foo() {}

fn foo() {
/// ```
/// ```
struct bar {}
}

/// ```
/// fn com() {
/// let i = 5;
///
/// let j = 6;
/// }
/// ```
fn foo() {}

fn foo() {
/// ```
/// fn com() {
/// let i = 5;
/// }
/// ```
struct bar {}
}