Skip to content

Trailing space on doc comment #6832

@Ciznia

Description

@Ciznia

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)

Metadata

Metadata

Assignees

Labels

A-doc-commentsArea: doc comments `/** */`, `#[doc = "..."]`, `///` and `//!`.A-whitespaceArea: whitespace and its handlingC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEE-needs-mcveCall for participation: this issue has a repro, but needs a Minimal Complete and Verifiable Example

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions