Skip to content

Commit

Permalink
fix: version gate changes for multiline single generic bound
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Jan 24, 2023
1 parent 6eeb4fd commit 5139b14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
23 changes: 12 additions & 11 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,21 +1057,22 @@ fn join_bounds_inner(
},
)?;

// Whether retry the function with forced newline is needed:
// Whether to retry with a forced newline:
// Only if result is not already multiline and did not exceed line width,
// and either there is more than one item;
// or the single item is of type `Trait`,
// and any of the internal arrays contains more than one item;
let retry_with_force_newline =
if force_newline || (!result.0.contains('\n') && result.0.len() <= shape.width) {
false
} else {
if items.len() > 1 {
true
} else {
is_item_with_multi_items_array(&items[0])
}
};
let retry_with_force_newline = match context.config.version() {
Version::One => {
!force_newline
&& items.len() > 1
&& (result.0.contains('\n') || result.0.len() > shape.width)
}
Version::Two if force_newline => false,
Version::Two if (!result.0.contains('\n') && result.0.len() <= shape.width) => false,
Version::Two if items.len() > 1 => true,
Version::Two => is_item_with_multi_items_array(&items[0]),
};

if retry_with_force_newline {
join_bounds_inner(context, shape, items, need_indent, true)
Expand Down
16 changes: 8 additions & 8 deletions tests/target/issue-4689/one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// Based on the issue description
pub trait PrettyPrinter<'tcx>:
Printer<
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
>
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
>
{
//
}
Expand Down

0 comments on commit 5139b14

Please sign in to comment.