rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Add `doc_comment_code_block_small_heuristics`, to override `use_small_heuristics` in doc code

Open joshtriplett opened this issue 5 months ago • 6 comments

This (unstable) configuration option allows overriding use_small_heuristics for doc code. This is particularly useful for code that wants to use use_small_heuristics = "Max" internally but present doctests and examples using use_small_heuristics = "Default".

This has come up before in the context of formatting the standard library, which uses use_small_heuristics = "Max" internally, but wants to present documentation and examples in the style most people will normally see.

joshtriplett avatar Jul 25 '25 22:07 joshtriplett

is doc_comment_code_block_width not enough to override the width settings when formatting code blocks?

ytmimi avatar Jul 28 '25 11:07 ytmimi

@ytmimi No, because if you're using use_small_heuristics = "Max", then the equivalent of doc_comment_code_block_small_heuristics = "Default" would require manually setting all the other widths that "Max" overrode.

joshtriplett avatar Jul 28 '25 11:07 joshtriplett

It wasn't originally clear to me but now I understand. You want a way to override all width settings when formatting code blocks in doc comments.

ytmimi avatar Jul 28 '25 23:07 ytmimi

It wasn't originally clear to me but now I understand. You want a way to override all width settings when formatting code blocks in doc comments.

Or in this case un-override them, yes.

I'm hoping to use this in rust-lang/rust, to be able to use the standard style in the standard library documentation.

joshtriplett avatar Jul 30 '25 19:07 joshtriplett

@ytmimi Done.

joshtriplett avatar Aug 06 '25 06:08 joshtriplett

Checking in on this: I'd love to use this (as an unstable flag) in a PR to format doc code blocks for std.

joshtriplett avatar Sep 14 '25 05:09 joshtriplett