Skip to content
Open
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ fn format_code_block(
let block_len = formatted
.snippet
.rfind('}')
// trim whitespace when using `fn_single_line=true`
.map(|i| {
formatted.snippet[..i]
.strip_suffix(char::is_whitespace)
.map_or(i, str::len)
})
.unwrap_or_else(|| formatted.snippet.len());

// It's possible that `block_len < FN_MAIN_PREFIX.len()`. This can happen if the code block was
Expand Down
12 changes: 12 additions & 0 deletions tests/target/issue-6832.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// rustfmt-format_code_in_doc_comments: true
// rustfmt-fn_single_line: true

/// ```rust
/// let font = String::from("hello");
/// ```
fn ascii_string() {}

/// ```rust
/// let font = String::from("hello 👋😁");
/// ```
fn unicode_chars() {}
Loading