rust-lang / rust-lang/rustfmt

Trailing space on doc comment

Open
#6,832 4 comments 0 reactions 1 assignee View on GitHub

@caelyreth is already working on this.

Since Apr 1, 2026.

A-doc-comments A-whitespace I-trailing-whitespace UO-fn_single_line UO-format_code_in_doc_comments
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Summary

I tried to format this code:

use std::{borrow::Cow, hash::Hash};

/// A CSS-like string value.
///
/// Used for `font-family`, `content` (pseudo-elements), custom identifiers,
/// and any other property that takes a textual value.
///
/// # Zero-copy for static strings
///
/// The inner `Cow<'static, str>` means proc_macro-generated code like:
/// ```rust
/// let font = Str::from_static("JetBrains Mono");
/// ```
/// involves **zero heap allocation** — the slice lives in the binary's
/// read-only data segment. Runtime-computed strings fall back to
/// [`Str::from_string`] which heap-allocates via `Cow::Owned`.
///
/// Two `Str` values are equal if their **contents** are equal, regardless
/// of whether one is borrowed and the other owned.
///
/// # Examples
///
/// ```rust
/// use oxidui_style::str::Str;
/// let a: Str = "monospace".into(); // static borrow, no alloc
/// let b = Str::from_string(format!("Font-{}", 42)); // heap-allocated
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct Str(pub Cow<'static, str>);
Expected behavior

I expect no change

Actual behavior

Add a trailing whitespace on the /// let font = Str::from_static("JetBrains Mono"); line
And then fail due to error_on_unformated=true

/// ```rust
/// let font = Str::from_static("JetBrains Mono"); 
/// ```

Configuration

rustfmt.toml

# Global config
edition = "2024"
style_edition = "2024"
unstable_features = true
newline_style = "Unix"

# Comment / Raw string formatting
error_on_unformatted = true
wrap_comments = true
format_strings = true
comment_width = 80
normalize_comments = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 80
normalize_doc_attributes = true

# code formatting config
error_on_line_overflow = true
max_width = 80

# Function / Struct / Enum / Trait formatting
brace_style = "SameLineWhere"
empty_item_single_line = true
fn_single_line = true
fn_params_layout = "Tall"
reorder_impl_items = true
type_punctuation_density = "Wide"
use_field_init_shorthand = true
overflow_delimited_expr = true

# Macro formatting
merge_derives = false

# Imports / Modules formatting
imports_layout = "HorizontalVertical"
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
reorder_imports = true
reorder_modules = true

# Control flow
control_brace_style = "AlwaysSameLine"
match_arm_blocks = true
match_arm_indent = true
match_block_trailing_comma = true
force_multiline_blocks = true

# Other
condense_wildcard_suffixes = true
hex_literal_case = "Upper"
tab_spaces = 4
trailing_comma = "Vertical"
trailing_semicolon = true
use_try_shorthand = true
float_literal_trailing_zero = "IfNoPostfix"

rustfmt cli options used (if applicable):

cargo +nightly fmt

Reproduction Steps

  1. Copy this code, and that config, and try to format it

Meta

cargo +nighlty fmt -- --version:

rustfmt 1.9.0-nightly (2d76d9bc76 2026-03-09)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.