Skip to content

fix: correct generic bound indentation [2.x/master] #4640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/formatting/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the code is structured, force_newline will always be false on the first pass through and a second pass is only triggered in situations where we have to use multiple lines to format. As such this index check only serves to cause a bug

shape
.block_indent(context.config.tab_spaces())
.with_max_width(context.config)
Expand Down Expand Up @@ -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)
Comment on lines +967 to +969
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither related to the underlying bug nor necessary to fix it, just noticed while in here that we were unnecessarily cloning the formatted bound

} 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,
),
}
};
Expand Down
13 changes: 13 additions & 0 deletions tests/source/issue_4636.rs
Original file line number Diff line number Diff line change
@@ -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
{
//
}
13 changes: 13 additions & 0 deletions tests/target/issue_4636.rs
Original file line number Diff line number Diff line change
@@ -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
{
//
}