diff --git a/src/items.rs b/src/items.rs index d4ed6ad670e..6af01bd1af1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -774,6 +774,20 @@ pub fn rewrite_type_alias(context: &RewriteContext, generics_span)); result.push_str(&generics_str); + + let where_budget = try_opt!(context.config + .max_width + .checked_sub(last_line_width(&result))); + let where_clause_str = try_opt!(rewrite_where_clause(context, + &generics.where_clause, + context.config, + context.config.item_brace_style, + indent, + where_budget, + context.config.where_density, + "=", + Some(span.hi))); + result.push_str(&where_clause_str); result.push_str(" = "); let line_width = last_line_width(&result); diff --git a/tests/source/type_alias.rs b/tests/source/type_alias.rs index d69375144e7..e4429bb8ddf 100644 --- a/tests/source/type_alias.rs +++ b/tests/source/type_alias.rs @@ -18,3 +18,10 @@ pub type CommentTest< /* Lifetime */ 'a // Type T > = (); + + +pub type WithWhereClause where T: Clone, LONGPARAMETERNAME: Clone + Eq + OtherTrait = Option; + +pub type Exactly100CharstoEqualWhereTest where T: Clone + Ord + Eq + SomeOtherTrait = Option; + +pub type Exactly101CharstoEqualWhereTest where T: Clone + Ord + Eq + SomeOtherTrait = Option; diff --git a/tests/target/type_alias.rs b/tests/target/type_alias.rs index d2d6bf4404d..d175aa60a67 100644 --- a/tests/target/type_alias.rs +++ b/tests/target/type_alias.rs @@ -38,3 +38,14 @@ pub type GenericsFitButNotEqualTest<'a, pub type CommentTest = (); + + +pub type WithWhereClause + where T: Clone, + LONGPARAMETERNAME: Clone + Eq + OtherTrait = Option; + +pub type Exactly100CharstoEqualWhereTest where T: Clone + Ord + Eq + SomeOtherTrait = + Option; + +pub type Exactly101CharstoEqualWhereTest + where T: Clone + Ord + Eq + SomeOtherTrait = Option;