Skip to content

Commit 567bd97

Browse files
authored
Document which comments are excluded from wrapping (#5637)
* Document which comments are excluded from wrapping Cf: #5634 * Add examples in wrap_commments doc * fix failling tests
1 parent 1d8491b commit 567bd97

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: Configurations.md

+20
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,10 @@ See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_s
29972997

29982998
Break comments to fit on the line
29992999

3000+
Note that no wrapping will happen if:
3001+
1. The comment is the start of a markdown header doc comment
3002+
2. An URL was found in the comment
3003+
30003004
- **Default value**: `false`
30013005
- **Possible values**: `true`, `false`
30023006
- **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347))
@@ -3011,6 +3015,11 @@ Break comments to fit on the line
30113015
// commodo consequat.
30123016

30133017
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3018+
3019+
// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3020+
3021+
/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it.
3022+
struct Foo {}
30143023
```
30153024

30163025
#### `true`:
@@ -3021,6 +3030,17 @@ Break comments to fit on the line
30213030
// magna aliqua. Ut enim ad minim veniam, quis nostrud
30223031
// exercitation ullamco laboris nisi ut aliquip ex ea
30233032
// commodo consequat.
3033+
3034+
// Lorem ipsum dolor sit amet, consectetur adipiscing elit,
3035+
// sed do eiusmod tempor incididunt ut labore et dolore
3036+
// magna aliqua. Ut enim ad minim veniam, quis nostrud
3037+
// exercitation ullamco laboris nisi ut aliquip ex ea
3038+
// commodo consequat.
3039+
3040+
// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3041+
3042+
/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it.
3043+
struct Foo {}
30243044
```
30253045

30263046
# Internal Options

Diff for: src/comment.rs

+2
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@ impl<'a> CommentRewrite<'a> {
801801
// 2) The comment is not the start of a markdown header doc comment
802802
// 3) The comment width exceeds the shape's width
803803
// 4) No URLS were found in the comment
804+
// If this changes, the documentation in ../Configurations.md#wrap_comments
805+
// should be changed accordingly.
804806
let should_wrap_comment = self.fmt.config.wrap_comments()
805807
&& !is_markdown_header_doc_comment
806808
&& unicode_str_width(line) > self.fmt.shape.width

0 commit comments

Comments
 (0)