@@ -622,7 +622,7 @@ impl<'a> FmtVisitor<'a> {
622622 fn need_empty_line ( a : & ast:: AssocItemKind , b : & ast:: AssocItemKind ) -> bool {
623623 match ( a, b) {
624624 ( TyAlias ( lty) , TyAlias ( rty) )
625- if both_type ( & lty. 3 , & rty. 3 ) || both_opaque ( & lty. 3 , & rty. 3 ) =>
625+ if both_type ( & lty. ty , & rty. ty ) || both_opaque ( & lty. ty , & rty. ty ) =>
626626 {
627627 false
628628 }
@@ -633,16 +633,16 @@ impl<'a> FmtVisitor<'a> {
633633
634634 buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. kind , & b. kind ) {
635635 ( TyAlias ( lty) , TyAlias ( rty) )
636- if both_type ( & lty. 3 , & rty. 3 ) || both_opaque ( & lty. 3 , & rty. 3 ) =>
636+ if both_type ( & lty. ty , & rty. ty ) || both_opaque ( & lty. ty , & rty. ty ) =>
637637 {
638638 a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
639639 }
640640 ( Const ( ..) , Const ( ..) ) | ( MacCall ( ..) , MacCall ( ..) ) => {
641641 a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
642642 }
643643 ( Fn ( ..) , Fn ( ..) ) => a. span . lo ( ) . cmp ( & b. span . lo ( ) ) ,
644- ( TyAlias ( ty) , _) if is_type ( & ty. 3 ) => Ordering :: Less ,
645- ( _, TyAlias ( ty) ) if is_type ( & ty. 3 ) => Ordering :: Greater ,
644+ ( TyAlias ( ty) , _) if is_type ( & ty. ty ) => Ordering :: Less ,
645+ ( _, TyAlias ( ty) ) if is_type ( & ty. ty ) => Ordering :: Greater ,
646646 ( TyAlias ( ..) , _) => Ordering :: Less ,
647647 ( _, TyAlias ( ..) ) => Ordering :: Greater ,
648648 ( Const ( ..) , _) => Ordering :: Less ,
@@ -679,7 +679,7 @@ pub(crate) fn format_impl(
679679 offset : Indent ,
680680) -> Option < String > {
681681 if let ast:: ItemKind :: Impl ( impl_kind) = & item. kind {
682- let ast:: ImplKind {
682+ let ast:: Impl {
683683 ref generics,
684684 ref self_ty,
685685 ref items,
@@ -833,7 +833,7 @@ fn format_impl_ref_and_type(
833833 offset : Indent ,
834834) -> Option < String > {
835835 if let ast:: ItemKind :: Impl ( impl_kind) = & item. kind {
836- let ast:: ImplKind {
836+ let ast:: Impl {
837837 unsafety,
838838 polarity,
839839 defaultness,
@@ -1029,8 +1029,13 @@ pub(crate) fn format_trait(
10291029 offset : Indent ,
10301030) -> Option < String > {
10311031 if let ast:: ItemKind :: Trait ( trait_kind) = & item. kind {
1032- let ast:: TraitKind ( is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
1033- * * trait_kind;
1032+ let ast:: Trait {
1033+ is_auto,
1034+ unsafety,
1035+ ref generics,
1036+ ref bounds,
1037+ ref items,
1038+ } = * * trait_kind;
10341039 let mut result = String :: with_capacity ( 128 ) ;
10351040 let header = format ! (
10361041 "{}{}{}trait " ,
@@ -1048,11 +1053,11 @@ pub(crate) fn format_trait(
10481053 result. push_str ( & generics_str) ;
10491054
10501055 // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
1051- if !generic_bounds . is_empty ( ) {
1056+ if !bounds . is_empty ( ) {
10521057 let ident_hi = context
10531058 . snippet_provider
10541059 . span_after ( item. span , & item. ident . as_str ( ) ) ;
1055- let bound_hi = generic_bounds . last ( ) . unwrap ( ) . span ( ) . hi ( ) ;
1060+ let bound_hi = bounds . last ( ) . unwrap ( ) . span ( ) . hi ( ) ;
10561061 let snippet = context. snippet ( mk_sp ( ident_hi, bound_hi) ) ;
10571062 if contains_comment ( snippet) {
10581063 return None ;
@@ -1061,7 +1066,7 @@ pub(crate) fn format_trait(
10611066 result = rewrite_assign_rhs_with (
10621067 context,
10631068 result + ":" ,
1064- generic_bounds ,
1069+ bounds ,
10651070 shape,
10661071 RhsTactics :: ForceNextLineWithoutIndent ,
10671072 ) ?;
@@ -1072,10 +1077,10 @@ pub(crate) fn format_trait(
10721077 let where_on_new_line = context. config . indent_style ( ) != IndentStyle :: Block ;
10731078
10741079 let where_budget = context. budget ( last_line_width ( & result) ) ;
1075- let pos_before_where = if generic_bounds . is_empty ( ) {
1080+ let pos_before_where = if bounds . is_empty ( ) {
10761081 generics. where_clause . span . lo ( )
10771082 } else {
1078- generic_bounds [ generic_bounds . len ( ) - 1 ] . span ( ) . hi ( )
1083+ bounds [ bounds . len ( ) - 1 ] . span ( ) . hi ( )
10791084 } ;
10801085 let option = WhereClauseOption :: snuggled ( & generics_str) ;
10811086 let where_clause_str = rewrite_where_clause (
@@ -1133,7 +1138,7 @@ pub(crate) fn format_trait(
11331138 result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
11341139 }
11351140 _ if context. config . empty_item_single_line ( )
1136- && trait_items . is_empty ( )
1141+ && items . is_empty ( )
11371142 && !result. contains ( '\n' )
11381143 && !contains_comment ( & snippet[ open_pos..] ) =>
11391144 {
@@ -1146,7 +1151,7 @@ pub(crate) fn format_trait(
11461151 BraceStyle :: PreferSameLine => result. push ( ' ' ) ,
11471152 BraceStyle :: SameLineWhere => {
11481153 if result. contains ( '\n' )
1149- || ( !generics. where_clause . predicates . is_empty ( ) && !trait_items . is_empty ( ) )
1154+ || ( !generics. where_clause . predicates . is_empty ( ) && !items . is_empty ( ) )
11501155 {
11511156 result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
11521157 } else {
@@ -1158,12 +1163,12 @@ pub(crate) fn format_trait(
11581163
11591164 let outer_indent_str = offset. block_only ( ) . to_string_with_newline ( context. config ) ;
11601165
1161- if !trait_items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1166+ if !items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
11621167 let mut visitor = FmtVisitor :: from_context ( context) ;
11631168 visitor. block_indent = offset. block_only ( ) . block_indent ( context. config ) ;
11641169 visitor. last_pos = block_span. lo ( ) + BytePos ( open_pos as u32 ) ;
11651170
1166- for item in trait_items {
1171+ for item in items {
11671172 visitor. visit_trait_item ( item) ;
11681173 }
11691174
@@ -1522,15 +1527,20 @@ struct TyAliasRewriteInfo<'c, 'g>(
15221527) ;
15231528
15241529pub ( crate ) fn rewrite_type_alias < ' a , ' b > (
1525- ty_alias_kind : & ast:: TyAliasKind ,
1530+ ty_alias_kind : & ast:: TyAlias ,
15261531 context : & RewriteContext < ' a > ,
15271532 indent : Indent ,
15281533 visitor_kind : & ItemVisitorKind < ' b > ,
15291534 span : Span ,
15301535) -> Option < String > {
15311536 use ItemVisitorKind :: * ;
15321537
1533- let ast:: TyAliasKind ( defaultness, ref generics, ref generic_bounds, ref ty) = * ty_alias_kind;
1538+ let ast:: TyAlias {
1539+ defaultness,
1540+ ref generics,
1541+ ref bounds,
1542+ ref ty,
1543+ } = * ty_alias_kind;
15341544 let ty_opt = ty. as_ref ( ) . map ( |t| & * * t) ;
15351545 let ( ident, vis) = match visitor_kind {
15361546 Item ( i) => ( i. ident , & i. vis ) ,
@@ -1545,17 +1555,17 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
15451555 // https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/items.md#type-aliases
15461556 match ( visitor_kind, ty_opt) {
15471557 ( Item ( _) , None ) => {
1548- let op_ty = OpaqueType { generic_bounds } ;
1549- rewrite_ty ( rw_info, Some ( generic_bounds ) , Some ( & op_ty) , vis)
1558+ let op_ty = OpaqueType { bounds } ;
1559+ rewrite_ty ( rw_info, Some ( bounds ) , Some ( & op_ty) , vis)
15501560 }
1551- ( Item ( _) , Some ( ty) ) => rewrite_ty ( rw_info, Some ( generic_bounds ) , Some ( & * ty) , vis) ,
1561+ ( Item ( _) , Some ( ty) ) => rewrite_ty ( rw_info, Some ( bounds ) , Some ( & * ty) , vis) ,
15521562 ( AssocImplItem ( _) , _) => {
15531563 let result = if let Some ( ast:: Ty {
1554- kind : ast:: TyKind :: ImplTrait ( _, ref generic_bounds ) ,
1564+ kind : ast:: TyKind :: ImplTrait ( _, ref bounds ) ,
15551565 ..
15561566 } ) = ty_opt
15571567 {
1558- let op_ty = OpaqueType { generic_bounds } ;
1568+ let op_ty = OpaqueType { bounds } ;
15591569 rewrite_ty ( rw_info, None , Some ( & op_ty) , & DEFAULT_VISIBILITY )
15601570 } else {
15611571 rewrite_ty ( rw_info, None , ty. as_ref ( ) , vis)
@@ -1566,7 +1576,7 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
15661576 }
15671577 }
15681578 ( AssocTraitItem ( _) , _) | ( ForeignItem ( _) , _) => {
1569- rewrite_ty ( rw_info, Some ( generic_bounds ) , ty. as_ref ( ) , vis)
1579+ rewrite_ty ( rw_info, Some ( bounds ) , ty. as_ref ( ) , vis)
15701580 }
15711581 }
15721582}
@@ -1891,13 +1901,13 @@ fn rewrite_static(
18911901 }
18921902}
18931903struct OpaqueType < ' a > {
1894- generic_bounds : & ' a ast:: GenericBounds ,
1904+ bounds : & ' a ast:: GenericBounds ,
18951905}
18961906
18971907impl < ' a > Rewrite for OpaqueType < ' a > {
18981908 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
18991909 let shape = shape. offset_left ( 5 ) ?; // `impl `
1900- self . generic_bounds
1910+ self . bounds
19011911 . rewrite ( context, shape)
19021912 . map ( |s| format ! ( "impl {}" , s) )
19031913 }
@@ -3126,17 +3136,22 @@ impl Rewrite for ast::ForeignItem {
31263136
31273137 let item_str = match self . kind {
31283138 ast:: ForeignItemKind :: Fn ( ref fn_kind) => {
3129- let ast:: FnKind ( defaultness, ref fn_sig, ref generics, ref block) = * * fn_kind;
3130- if let Some ( ref body) = block {
3139+ let ast:: Fn {
3140+ defaultness,
3141+ ref sig,
3142+ ref generics,
3143+ ref body,
3144+ } = * * fn_kind;
3145+ if let Some ( ref body) = body {
31313146 let mut visitor = FmtVisitor :: from_context ( context) ;
31323147 visitor. block_indent = shape. indent ;
31333148 visitor. last_pos = self . span . lo ( ) ;
31343149 let inner_attrs = inner_attributes ( & self . attrs ) ;
31353150 let fn_ctxt = visit:: FnCtxt :: Foreign ;
31363151 visitor. visit_fn (
3137- visit:: FnKind :: Fn ( fn_ctxt, self . ident , fn_sig , & self . vis , Some ( body) ) ,
3152+ visit:: FnKind :: Fn ( fn_ctxt, self . ident , & sig , & self . vis , Some ( body) ) ,
31383153 generics,
3139- & fn_sig . decl ,
3154+ & sig . decl ,
31403155 self . span ,
31413156 defaultness,
31423157 Some ( & inner_attrs) ,
@@ -3147,7 +3162,7 @@ impl Rewrite for ast::ForeignItem {
31473162 context,
31483163 shape. indent ,
31493164 self . ident ,
3150- & FnSig :: from_method_sig ( fn_sig , generics, & self . vis ) ,
3165+ & FnSig :: from_method_sig ( & sig , generics, & self . vis ) ,
31513166 span,
31523167 FnBraceStyle :: None ,
31533168 )
0 commit comments