Fix #5234 - handling of empty code block (#5601)

This commit is contained in:
David Bar-On 2023-01-29 20:55:14 +02:00 committed by GitHub
parent bcfc57ec8a
commit b08130c590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 1 deletions

View File

@ -726,7 +726,7 @@ fn handle_line(
let code_block = match self.code_block_attr.as_ref().unwrap() { let code_block = match self.code_block_attr.as_ref().unwrap() {
CodeBlockAttribute::Rust CodeBlockAttribute::Rust
if self.fmt.config.format_code_in_doc_comments() 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(); let mut config = self.fmt.config.clone();
config.set().wrap_comments(false); config.set().wrap_comments(false);

View File

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

View File

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