@@ -836,8 +836,7 @@ pub(crate) fn format_impl(
836836 let where_span_end = context. snippet_provider . opt_span_before ( missing_span, "{" ) ;
837837 let where_clause_str = rewrite_where_clause (
838838 context,
839- & generics. where_clause . predicates ,
840- generics. where_clause . span ,
839+ & generics. where_clause ,
841840 context. config . brace_style ( ) ,
842841 Shape :: legacy ( where_budget, offset. block_only ( ) ) ,
843842 false ,
@@ -1224,8 +1223,7 @@ pub(crate) fn format_trait(
12241223 let option = WhereClauseOption :: snuggled ( & generics_str) ;
12251224 let where_clause_str = rewrite_where_clause (
12261225 context,
1227- & generics. where_clause . predicates ,
1228- generics. where_clause . span ,
1226+ & generics. where_clause ,
12291227 context. config . brace_style ( ) ,
12301228 Shape :: legacy ( where_budget, offset. block_only ( ) ) ,
12311229 where_on_new_line,
@@ -1350,8 +1348,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> {
13501348
13511349 let where_str = rewrite_where_clause (
13521350 context,
1353- & self . generics . where_clause . predicates ,
1354- self . generics . where_clause . span ,
1351+ & self . generics . where_clause ,
13551352 context. config . brace_style ( ) ,
13561353 shape,
13571354 false ,
@@ -1621,8 +1618,7 @@ fn format_tuple_struct(
16211618 let option = WhereClauseOption :: new ( true , WhereClauseSpace :: Newline ) ;
16221619 rewrite_where_clause (
16231620 context,
1624- & generics. where_clause . predicates ,
1625- generics. where_clause . span ,
1621+ & generics. where_clause ,
16261622 context. config . brace_style ( ) ,
16271623 Shape :: legacy ( where_budget, offset. block_only ( ) ) ,
16281624 false ,
@@ -1691,7 +1687,7 @@ struct TyAliasRewriteInfo<'c, 'g>(
16911687 & ' c RewriteContext < ' c > ,
16921688 Indent ,
16931689 & ' g ast:: Generics ,
1694- ast:: TyAliasWhereClauses ,
1690+ & ' g ast:: WhereClause ,
16951691 symbol:: Ident ,
16961692 Span ,
16971693) ;
@@ -1712,13 +1708,13 @@ pub(crate) fn rewrite_type_alias<'a>(
17121708 ref generics,
17131709 ref bounds,
17141710 ref ty,
1715- where_clauses ,
1711+ ref after_where_clause ,
17161712 } = * ty_alias_kind;
17171713 let ty_opt = ty. as_ref ( ) ;
17181714 let rhs_hi = ty
17191715 . as_ref ( )
1720- . map_or ( where_clauses . before . span . hi ( ) , |ty| ty. span . hi ( ) ) ;
1721- let rw_info = & TyAliasRewriteInfo ( context, indent, generics, where_clauses , ident, span) ;
1716+ . map_or ( generics . where_clause . span . hi ( ) , |ty| ty. span . hi ( ) ) ;
1717+ let rw_info = & TyAliasRewriteInfo ( context, indent, generics, after_where_clause , ident, span) ;
17221718 let op_ty = opaque_ty ( ty) ;
17231719 // Type Aliases are formatted slightly differently depending on the context
17241720 // in which they appear, whether they are opaque, and whether they are associated.
@@ -1762,11 +1758,7 @@ fn rewrite_ty<R: Rewrite>(
17621758 vis : & ast:: Visibility ,
17631759) -> RewriteResult {
17641760 let mut result = String :: with_capacity ( 128 ) ;
1765- let TyAliasRewriteInfo ( context, indent, generics, where_clauses, ident, span) = * rw_info;
1766- let ( before_where_predicates, after_where_predicates) = generics
1767- . where_clause
1768- . predicates
1769- . split_at ( where_clauses. split ) ;
1761+ let TyAliasRewriteInfo ( context, indent, generics, after_where_clause, ident, span) = * rw_info;
17701762 result. push_str ( & format ! ( "{}type " , format_visibility( context, vis) ) ) ;
17711763 let ident_str = rewrite_ident ( context, ident) ;
17721764
@@ -1804,8 +1796,7 @@ fn rewrite_ty<R: Rewrite>(
18041796 }
18051797 let before_where_clause_str = rewrite_where_clause (
18061798 context,
1807- before_where_predicates,
1808- where_clauses. before . span ,
1799+ & generics. where_clause ,
18091800 context. config . brace_style ( ) ,
18101801 Shape :: legacy ( where_budget, indent) ,
18111802 false ,
@@ -1820,9 +1811,9 @@ fn rewrite_ty<R: Rewrite>(
18201811 // If there are any where clauses, add a newline before the assignment.
18211812 // If there is a before where clause, do not indent, but if there is
18221813 // only an after where clause, additionally indent the type.
1823- if !before_where_predicates . is_empty ( ) {
1814+ if !generics . where_clause . predicates . is_empty ( ) {
18241815 result. push_str ( & indent. to_string_with_newline ( context. config ) ) ;
1825- } else if !after_where_predicates . is_empty ( ) {
1816+ } else if !after_where_clause . predicates . is_empty ( ) {
18261817 result. push_str (
18271818 & indent
18281819 . block_indent ( context. config )
@@ -1835,7 +1826,7 @@ fn rewrite_ty<R: Rewrite>(
18351826 let comment_span = context
18361827 . snippet_provider
18371828 . opt_span_before ( span, "=" )
1838- . map ( |op_lo| mk_sp ( where_clauses . before . span . hi ( ) , op_lo) ) ;
1829+ . map ( |op_lo| mk_sp ( generics . where_clause . span . hi ( ) , op_lo) ) ;
18391830
18401831 let lhs = match comment_span {
18411832 Some ( comment_span)
@@ -1846,7 +1837,7 @@ fn rewrite_ty<R: Rewrite>(
18461837 . unknown_error ( ) ?,
18471838 ) =>
18481839 {
1849- let comment_shape = if !before_where_predicates . is_empty ( ) {
1840+ let comment_shape = if !generics . where_clause . predicates . is_empty ( ) {
18501841 Shape :: indented ( indent, context. config )
18511842 } else {
18521843 let shape = Shape :: indented ( indent, context. config ) ;
@@ -1869,7 +1860,7 @@ fn rewrite_ty<R: Rewrite>(
18691860
18701861 // 1 = `;` unless there's a trailing where clause
18711862 let shape = Shape :: indented ( indent, context. config ) ;
1872- let shape = if after_where_predicates . is_empty ( ) {
1863+ let shape = if after_where_clause . predicates . is_empty ( ) {
18731864 Shape :: indented ( indent, context. config )
18741865 . sub_width ( 1 )
18751866 . max_width_error ( shape. width , span) ?
@@ -1881,12 +1872,11 @@ fn rewrite_ty<R: Rewrite>(
18811872 result
18821873 } ;
18831874
1884- if !after_where_predicates . is_empty ( ) {
1875+ if !after_where_clause . predicates . is_empty ( ) {
18851876 let option = WhereClauseOption :: new ( true , WhereClauseSpace :: Newline ) ;
18861877 let after_where_clause_str = rewrite_where_clause (
18871878 context,
1888- after_where_predicates,
1889- where_clauses. after . span ,
1879+ & after_where_clause,
18901880 context. config . brace_style ( ) ,
18911881 Shape :: indented ( indent, context. config ) ,
18921882 false ,
@@ -2728,8 +2718,7 @@ fn rewrite_fn_base(
27282718 }
27292719 let where_clause_str = rewrite_where_clause (
27302720 context,
2731- & where_clause. predicates ,
2732- where_clause. span ,
2721+ & where_clause,
27332722 context. config . brace_style ( ) ,
27342723 Shape :: indented ( indent, context. config ) ,
27352724 true ,
@@ -3158,8 +3147,7 @@ fn rewrite_bounds_on_where_clause(
31583147
31593148fn rewrite_where_clause (
31603149 context : & RewriteContext < ' _ > ,
3161- predicates : & [ ast:: WherePredicate ] ,
3162- where_span : Span ,
3150+ where_clause : & ast:: WhereClause ,
31633151 brace_style : BraceStyle ,
31643152 shape : Shape ,
31653153 on_new_line : bool ,
@@ -3168,6 +3156,12 @@ fn rewrite_where_clause(
31683156 span_end_before_where : BytePos ,
31693157 where_clause_option : WhereClauseOption ,
31703158) -> RewriteResult {
3159+ let ast:: WhereClause {
3160+ ref predicates,
3161+ span : where_span,
3162+ has_where_token : _,
3163+ } = * where_clause;
3164+
31713165 if predicates. is_empty ( ) {
31723166 return Ok ( String :: new ( ) ) ;
31733167 }
@@ -3354,8 +3348,7 @@ fn format_generics(
33543348 }
33553349 let where_clause_str = rewrite_where_clause (
33563350 context,
3357- & generics. where_clause . predicates ,
3358- generics. where_clause . span ,
3351+ & generics. where_clause ,
33593352 brace_style,
33603353 Shape :: legacy ( budget, offset. block_only ( ) ) ,
33613354 true ,
0 commit comments