File tree 9 files changed +131
-0
lines changed
9 files changed +131
-0
lines changed Original file line number Diff line number Diff line change @@ -926,6 +926,14 @@ fn add_one(x: i32) -> i32 {
926
926
}
927
927
```
928
928
929
+ ## ` doc_comment_code_block_width `
930
+
931
+ Max width for code snippets included in doc comments. Only used if [ ` format_code_in_doc_comments ` ] ( #format_code_in_doc_comments ) is true.
932
+
933
+ - ** Default value** : ` 100 `
934
+ - ** Possible values** : any positive integer that is less than or equal to the value specified for [ ` max_width ` ] ( #max_width )
935
+ - ** Stable** : No (tracking issue: [ #5359 ] ( https://github.com/rust-lang/rustfmt/issues/5359 ) )
936
+
929
937
## ` format_generated_files `
930
938
931
939
Format generated files. A file is considered generated
Original file line number Diff line number Diff line change @@ -730,6 +730,10 @@ impl<'a> CommentRewrite<'a> {
730
730
{
731
731
let mut config = self . fmt . config . clone ( ) ;
732
732
config. set ( ) . wrap_comments ( false ) ;
733
+ let comment_max_width = config
734
+ . doc_comment_code_block_width ( )
735
+ . min ( config. max_width ( ) ) ;
736
+ config. set ( ) . max_width ( comment_max_width) ;
733
737
if let Some ( s) =
734
738
crate :: format_code_block ( & self . code_block_buffer , & config, false )
735
739
{
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ create_config! {
57
57
// Comments. macros, and strings
58
58
wrap_comments: bool , false , false , "Break comments to fit on the line" ;
59
59
format_code_in_doc_comments: bool , false , false , "Format the code snippet in doc comments." ;
60
+ doc_comment_code_block_width: usize , 100 , false , "Maximum width for code snippets in doc \
61
+ comments. No effect unless format_code_in_doc_comments = true";
60
62
comment_width: usize , 80 , false ,
61
63
"Maximum length of comments. No effect unless wrap_comments = true" ;
62
64
normalize_comments: bool , false , false , "Convert /* */ comments to // comments where possible" ;
@@ -532,6 +534,7 @@ chain_width = 60
532
534
single_line_if_else_max_width = 50
533
535
wrap_comments = false
534
536
format_code_in_doc_comments = false
537
+ doc_comment_code_block_width = 100
535
538
comment_width = 80
536
539
normalize_comments = false
537
540
normalize_doc_attributes = false
Original file line number Diff line number Diff line change
1
+ // rustfmt-format_code_in_doc_comments: true
2
+ // rustfmt-doc_comment_code_block_width: 100
3
+
4
+ /// ```rust
5
+ /// impl Test {
6
+ /// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
7
+ /// Self::from_bytes_manual_slice(v, 0, v.len() )
8
+ /// }
9
+ /// }
10
+ /// ```
11
+
12
+ impl Test {
13
+ pub const fn from_bytes ( v : & [ u8 ] ) -> Result < Self , ParserError > {
14
+ Self :: from_bytes_manual_slice ( v, 0 , v. len ( ) )
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 50
2
+ // rustfmt-format_code_in_doc_comments: true
3
+ // rustfmt-doc_comment_code_block_width: 100
4
+
5
+ /// ```rust
6
+ /// impl Test {
7
+ /// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
8
+ /// Self::from_bytes_manual_slice(v, 0, v.len() )
9
+ /// }
10
+ /// }
11
+ /// ```
12
+
13
+ impl Test {
14
+ pub const fn from_bytes ( v : & [ u8 ] ) -> Result < Self , ParserError > {
15
+ Self :: from_bytes_manual_slice ( v, 0 , v. len ( ) )
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-format_code_in_doc_comments: true
2
+ // rustfmt-doc_comment_code_block_width: 50
3
+
4
+ /// ```rust
5
+ /// impl Test {
6
+ /// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
7
+ /// Self::from_bytes_manual_slice(v, 0, v.len() )
8
+ /// }
9
+ /// }
10
+ /// ```
11
+
12
+ impl Test {
13
+ pub const fn from_bytes ( v : & [ u8 ] ) -> Result < Self , ParserError > {
14
+ Self :: from_bytes_manual_slice ( v, 0 , v. len ( ) )
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-format_code_in_doc_comments: true
2
+ // rustfmt-doc_comment_code_block_width: 100
3
+
4
+ /// ```rust
5
+ /// impl Test {
6
+ /// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
7
+ /// Self::from_bytes_manual_slice(v, 0, v.len())
8
+ /// }
9
+ /// }
10
+ /// ```
11
+
12
+ impl Test {
13
+ pub const fn from_bytes ( v : & [ u8 ] ) -> Result < Self , ParserError > {
14
+ Self :: from_bytes_manual_slice ( v, 0 , v. len ( ) )
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 50
2
+ // rustfmt-format_code_in_doc_comments: true
3
+ // rustfmt-doc_comment_code_block_width: 100
4
+
5
+ /// ```rust
6
+ /// impl Test {
7
+ /// pub const fn from_bytes(
8
+ /// v: &[u8],
9
+ /// ) -> Result<Self, ParserError> {
10
+ /// Self::from_bytes_manual_slice(
11
+ /// v,
12
+ /// 0,
13
+ /// v.len(),
14
+ /// )
15
+ /// }
16
+ /// }
17
+ /// ```
18
+
19
+ impl Test {
20
+ pub const fn from_bytes (
21
+ v : & [ u8 ] ,
22
+ ) -> Result < Self , ParserError > {
23
+ Self :: from_bytes_manual_slice (
24
+ v,
25
+ 0 ,
26
+ v. len ( ) ,
27
+ )
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-format_code_in_doc_comments: true
2
+ // rustfmt-doc_comment_code_block_width: 50
3
+
4
+ /// ```rust
5
+ /// impl Test {
6
+ /// pub const fn from_bytes(
7
+ /// v: &[u8],
8
+ /// ) -> Result<Self, ParserError> {
9
+ /// Self::from_bytes_manual_slice(
10
+ /// v,
11
+ /// 0,
12
+ /// v.len(),
13
+ /// )
14
+ /// }
15
+ /// }
16
+ /// ```
17
+
18
+ impl Test {
19
+ pub const fn from_bytes ( v : & [ u8 ] ) -> Result < Self , ParserError > {
20
+ Self :: from_bytes_manual_slice ( v, 0 , v. len ( ) )
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments