-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent enum variant attributes from wrapping one character early
Fixes 5801 when using `version=Two` Previously, doc comments would wrap one character less than the `comment_width` when using `wrap_comments=true`, and fn-like attributes would wrap one character before the `attr_fn_like_width`. Now, when using `version=Two` enum variant attributes won't wrap early
- Loading branch information
Showing
9 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
max_width = 120 | ||
version = "One" | ||
attr_fn_like_width = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
max_width = 120 | ||
version = "Two" | ||
attr_fn_like_width = 120 |
8 changes: 8 additions & 0 deletions
8
tests/source/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-config: issue-5801-v1.toml | ||
|
||
pub enum Severity { | ||
#[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)] | ||
AttrsWillWrap, | ||
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)] | ||
AttrsWontWrap, | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// rustfmt-comment_width: 120 | ||
// rustfmt-wrap_comments: true | ||
// rustfmt-max_width: 120 | ||
// rustfmt-version: One | ||
|
||
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine | ||
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { | ||
unimplemented!() | ||
} | ||
|
||
pub enum Severity { | ||
/// In version one, the below line got wrapped prematurely as we subtracted 1 to account for `,`. See issue #5801. | ||
/// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines still. | ||
Error, | ||
/// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem. | ||
Warning, | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/target/issue-5801/attribute_does_not_wrap_within_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-config: issue-5801-v2.toml | ||
|
||
pub enum Severity { | ||
#[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)] | ||
AttrsWillWrap, | ||
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)] | ||
AttrsWontWrap, | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/target/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// rustfmt-config: issue-5801-v1.toml | ||
|
||
pub enum Severity { | ||
#[something( | ||
AAAAAAAAAAAAA, | ||
BBBBBBBBBBBBBB, | ||
CCCCCCCCCCCCCCCC, | ||
DDDDDDDDDDDDD, | ||
EEEEEEEEEEEE, | ||
FFFFFFFFFFF, | ||
GGGGGGGGGGG | ||
)] | ||
AttrsWillWrap, | ||
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)] | ||
AttrsWontWrap, | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/target/issue-5801/comment_does_not_wrap_within_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// rustfmt-comment_width: 120 | ||
// rustfmt-wrap_comments: true | ||
// rustfmt-max_width: 120 | ||
// rustfmt-version: Two | ||
|
||
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine | ||
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { | ||
unimplemented!() | ||
} | ||
|
||
pub enum Severity { | ||
/// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines still. | ||
Error, | ||
/// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem. | ||
Warning, | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/target/issue-5801/comment_unexpectedly_wraps_before_max_width.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// rustfmt-comment_width: 120 | ||
// rustfmt-wrap_comments: true | ||
// rustfmt-max_width: 120 | ||
// rustfmt-version: One | ||
|
||
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine | ||
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { | ||
unimplemented!() | ||
} | ||
|
||
pub enum Severity { | ||
/// In version one, the below line got wrapped prematurely as we subtracted 1 to account for `,`. See issue #5801. | ||
/// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines | ||
/// still. | ||
Error, | ||
/// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem. | ||
Warning, | ||
} |