From b6f5b6200be7616c625dee27848628b6d5016074 Mon Sep 17 00:00:00 2001 From: John Chen Date: Sun, 18 Aug 2024 09:11:19 -0400 Subject: [PATCH] Issue-5892: Type alias generic rewrite follows the same rule as trait rewrite --- src/items.rs | 21 +++++++++++++++++---- tests/source/issue-5892.rs | 33 +++++++++++++++++++++++++++++++++ tests/target/issue-5892.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 tests/source/issue-5892.rs create mode 100644 tests/target/issue-5892.rs diff --git a/src/items.rs b/src/items.rs index 35591df0fd8..5ab37b6b669 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1768,10 +1768,23 @@ fn rewrite_ty( if let Some(bounds) = generic_bounds_opt { if !bounds.is_empty() { - // 2 = `: ` - let shape = Shape::indented(indent, context.config).offset_left(result.len() + 2)?; - let type_bounds = bounds.rewrite(context, shape).map(|s| format!(": {}", s))?; - result.push_str(&type_bounds); + if context.config.style_edition() <= StyleEdition::Edition2021 { + // 2 = `: ` + let shape = + Shape::indented(indent, context.config).offset_left(result.len() + 2)?; + let type_bounds = bounds.rewrite(context, shape).map(|s| format!(": {}", s))?; + result.push_str(&type_bounds); + } else { + let shape = Shape::indented(indent, context.config).offset_left(result.len())?; + result = rewrite_assign_rhs_with( + context, + result.clone() + ":", + bounds, + shape, + &RhsAssignKind::Bounds, + RhsTactics::ForceNextLineWithoutIndent, + )?; + } } } diff --git a/tests/source/issue-5892.rs b/tests/source/issue-5892.rs new file mode 100644 index 00000000000..2be61afb5fb --- /dev/null +++ b/tests/source/issue-5892.rs @@ -0,0 +1,33 @@ +// rustfmt-style_edition: 2024 + +type AAAAAAAAAAAAA: + BBBBBBBBBBBBBBB< + CCCCCCCCCCCCCCCCC, + DDDDDDDDDDDDDDDDD, + EEEEEEEEEEEEEEEEE, + FFFFFFFFFFFFFFFFF, + GGGGGGGGGGGGGGGGG, + HHHHHHHHHHHHHHHHH, + IIIIIIIIIIIIIIIII, + >; + +type AAAAAAAAAAAAA: + BBBBBBBBBBBBBBB< + CCCCCCCCCCCCCCCCC, + DDDDDDDDDDDDDDDDD, + EEEEEEEEEEEEEEEEE, + FFFFFFFFFFFFFFFFF, + GGGGGGGGGGGGGGGGG, + HHHHHHHHHHHHHHHHH, + IIIIIIIIIIIIIIIII, + > + Eq + + PartialEq; + +// previous error: maximum length exceeded +type SomeType: + BBBBBBBBBBBBBBB + + AAAAAAAAAAAAA; + +// previous error: maximum length exceeded +type SomeType: + BBBBBBBBBBBBBBB; diff --git a/tests/target/issue-5892.rs b/tests/target/issue-5892.rs new file mode 100644 index 00000000000..2be61afb5fb --- /dev/null +++ b/tests/target/issue-5892.rs @@ -0,0 +1,33 @@ +// rustfmt-style_edition: 2024 + +type AAAAAAAAAAAAA: + BBBBBBBBBBBBBBB< + CCCCCCCCCCCCCCCCC, + DDDDDDDDDDDDDDDDD, + EEEEEEEEEEEEEEEEE, + FFFFFFFFFFFFFFFFF, + GGGGGGGGGGGGGGGGG, + HHHHHHHHHHHHHHHHH, + IIIIIIIIIIIIIIIII, + >; + +type AAAAAAAAAAAAA: + BBBBBBBBBBBBBBB< + CCCCCCCCCCCCCCCCC, + DDDDDDDDDDDDDDDDD, + EEEEEEEEEEEEEEEEE, + FFFFFFFFFFFFFFFFF, + GGGGGGGGGGGGGGGGG, + HHHHHHHHHHHHHHHHH, + IIIIIIIIIIIIIIIII, + > + Eq + + PartialEq; + +// previous error: maximum length exceeded +type SomeType: + BBBBBBBBBBBBBBB + + AAAAAAAAAAAAA; + +// previous error: maximum length exceeded +type SomeType: + BBBBBBBBBBBBBBB;