From 2f3aada19551f8bc14ba9bb3939ab101d190b1f2 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Tue, 12 Jan 2021 17:39:03 -0600 Subject: [PATCH 1/2] fix: indentation issue on generic bounds --- src/formatting/types.rs | 2 +- tests/source/issue_4636.rs | 13 +++++++++++++ tests/target/issue_4636.rs | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue_4636.rs create mode 100644 tests/target/issue_4636.rs diff --git a/src/formatting/types.rs b/src/formatting/types.rs index d9802ea5f45..1f8295b64cf 100644 --- a/src/formatting/types.rs +++ b/src/formatting/types.rs @@ -933,7 +933,7 @@ fn join_bounds_inner( _ => false, }; - let shape = if i > 0 && need_indent && force_newline { + let shape = if need_indent && force_newline { shape .block_indent(context.config.tab_spaces()) .with_max_width(context.config) diff --git a/tests/source/issue_4636.rs b/tests/source/issue_4636.rs new file mode 100644 index 00000000000..ea7079f6c73 --- /dev/null +++ b/tests/source/issue_4636.rs @@ -0,0 +1,13 @@ +pub trait PrettyPrinter<'tcx>: + Printer< + 'tcx, + Error = fmt::Error, + Path = Self, + Region = Self, + Type = Self, + DynExistential = Self, + Const = Self, + > + fmt::Write + { + // + } \ No newline at end of file diff --git a/tests/target/issue_4636.rs b/tests/target/issue_4636.rs new file mode 100644 index 00000000000..a6465e29a02 --- /dev/null +++ b/tests/target/issue_4636.rs @@ -0,0 +1,13 @@ +pub trait PrettyPrinter<'tcx>: + Printer< + 'tcx, + Error = fmt::Error, + Path = Self, + Region = Self, + Type = Self, + DynExistential = Self, + Const = Self, + > + fmt::Write +{ + // +} From 198905dee9187a4548dce81fd534f7c7057fd441 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Tue, 12 Jan 2021 17:40:53 -0600 Subject: [PATCH 2/2] refactor: remove unneeded clone --- src/formatting/types.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/formatting/types.rs b/src/formatting/types.rs index 1f8295b64cf..f356e7a2e75 100644 --- a/src/formatting/types.rs +++ b/src/formatting/types.rs @@ -964,22 +964,21 @@ fn join_bounds_inner( joiner }; - let (trailing_str, extendable) = if i == 0 { + let (extendable, trailing_str) = if i == 0 { let bound_str = item.rewrite(context, shape)?; - let bound_str_clone = bound_str.clone(); - (bound_str, is_bound_extendable(&bound_str_clone, item)) + (is_bound_extendable(&bound_str, item), bound_str) } else { let bound_str = &item.rewrite(context, shape)?; match leading_span { Some(ls) if has_leading_comment => ( + is_bound_extendable(bound_str, item), combine_strs_with_missing_comments( context, joiner, bound_str, ls, shape, true, )?, - is_bound_extendable(bound_str, item), ), _ => ( - String::from(joiner) + bound_str, is_bound_extendable(bound_str, item), + String::from(joiner) + bound_str, ), } };