From cf663dbfdf99a9ec61e6a4d9995a1443153ded81 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 23 Dec 2022 15:52:17 +0100 Subject: [PATCH 1/3] Document which comments are excluded from wrapping Cf: https://github.com/rust-lang/rustfmt/issues/5634 --- Configurations.md | 4 ++++ src/comment.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Configurations.md b/Configurations.md index 49e7e4e6489..d680dd061e4 100644 --- a/Configurations.md +++ b/Configurations.md @@ -3001,6 +3001,10 @@ Break comments to fit on the line - **Possible values**: `true`, `false` - **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347)) +Note that no wrapping will happen if: +1. The comment is the start of a markdown header doc comment +2. An URL was found in the comment + #### `false` (default): ```rust diff --git a/src/comment.rs b/src/comment.rs index 4d565afc1e0..261fa5e93d8 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -801,6 +801,8 @@ impl<'a> CommentRewrite<'a> { // 2) The comment is not the start of a markdown header doc comment // 3) The comment width exceeds the shape's width // 4) No URLS were found in the comment + // If this changes, the documentation in ../Configurations.md#wrap_comments + // should be changed accordingly. let should_wrap_comment = self.fmt.config.wrap_comments() && !is_markdown_header_doc_comment && unicode_str_width(line) > self.fmt.shape.width From 28a663d184328ff2d5e6f495be43fc80eac1e4bd Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Mon, 2 Jan 2023 17:00:23 +0100 Subject: [PATCH 2/3] Add examples in wrap_commments doc --- Configurations.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Configurations.md b/Configurations.md index d680dd061e4..bafbfd8f42c 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2997,14 +2997,14 @@ See also [`brace_style`](#brace_style), [`control_brace_style`](#control_brace_s Break comments to fit on the line -- **Default value**: `false` -- **Possible values**: `true`, `false` -- **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347)) - Note that no wrapping will happen if: 1. The comment is the start of a markdown header doc comment 2. An URL was found in the comment +- **Default value**: `false` +- **Possible values**: `true`, `false` +- **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347)) + #### `false` (default): ```rust @@ -3015,6 +3015,10 @@ Note that no wrapping will happen if: // commodo consequat. // 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. + +// # This 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. + +// 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. ``` #### `true`: @@ -3025,6 +3029,16 @@ Note that no wrapping will happen if: // magna aliqua. Ut enim ad minim veniam, quis nostrud // exercitation ullamco laboris nisi ut aliquip ex ea // commodo consequat. + +// 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. + +// # This 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. + +// 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. ``` # Internal Options From 151861cdc6499c298e9f81657a993027916d3835 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Mon, 2 Jan 2023 17:18:02 +0100 Subject: [PATCH 3/3] fix failling tests --- Configurations.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Configurations.md b/Configurations.md index bafbfd8f42c..ac638ff91e6 100644 --- a/Configurations.md +++ b/Configurations.md @@ -3016,9 +3016,10 @@ Note that no wrapping will happen if: // 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. -// # This 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. - // 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. + +/// # 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. +struct Foo {} ``` #### `true`: @@ -3036,9 +3037,10 @@ Note that no wrapping will happen if: // exercitation ullamco laboris nisi ut aliquip ex ea // commodo consequat. -// # This 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. - // 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. + +/// # 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. +struct Foo {} ``` # Internal Options