From 0221eac9faa51d78629af1c31f55724853d442ea Mon Sep 17 00:00:00 2001 From: Flowrey Date: Fri, 29 Mar 2024 15:11:25 +0100 Subject: [PATCH] Draft: fix: Fn supertraits indentation --- src/expr.rs | 12 +++++++++++- tests/source/issue-6127.rs | 9 +++++++++ tests/target/issue-6127.rs | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-6127.rs create mode 100644 tests/target/issue-6127.rs diff --git a/src/expr.rs b/src/expr.rs index 6a21d88ac9d..498779982fb 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -2110,7 +2110,7 @@ fn choose_rhs( expr: &R, shape: Shape, orig_rhs: Option, - _rhs_kind: &RhsAssignKind<'_>, + rhs_kind: &RhsAssignKind<'_>, rhs_tactics: RhsTactics, has_rhs_comment: bool, ) -> Option { @@ -2141,6 +2141,16 @@ fn choose_rhs( (Some(ref orig_rhs), Some(ref new_rhs)) if prefer_next_line(orig_rhs, new_rhs, rhs_tactics) => { + if let RhsAssignKind::Bounds = rhs_kind { + if new_rhs.contains("->") { + return Some( + new_rhs + .lines() + .map(|l| format!("{new_indent_str}{l}")) + .join(""), + ); + } + } Some(format!("{new_indent_str}{new_rhs}")) } (None, Some(ref new_rhs)) => Some(format!("{new_indent_str}{new_rhs}")), diff --git a/tests/source/issue-6127.rs b/tests/source/issue-6127.rs new file mode 100644 index 00000000000..15497a7492c --- /dev/null +++ b/tests/source/issue-6127.rs @@ -0,0 +1,9 @@ +trait Foo: + Fn( + ReallyLongTypeName, + ReallyLongTypeName, + ReallyLongTypeName, + ReallyLongTypeName, +) -> ReallyLongTypeName +{ +} diff --git a/tests/target/issue-6127.rs b/tests/target/issue-6127.rs new file mode 100644 index 00000000000..01ad21a4200 --- /dev/null +++ b/tests/target/issue-6127.rs @@ -0,0 +1,9 @@ +trait Foo: + Fn( + ReallyLongTypeName, + ReallyLongTypeName, + ReallyLongTypeName, + ReallyLongTypeName, + ) -> ReallyLongTypeName +{ +}