@@ -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 (
@@ -1134,7 +1139,7 @@ pub(crate) fn format_trait(
11341139 BraceStyle :: PreferSameLine => result. push ( ' ' ) ,
11351140 BraceStyle :: SameLineWhere => {
11361141 if result. contains ( '\n' )
1137- || ( !generics. where_clause . predicates . is_empty ( ) && !trait_items . is_empty ( ) )
1142+ || ( !generics. where_clause . predicates . is_empty ( ) && !items . is_empty ( ) )
11381143 {
11391144 result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
11401145 } else {
@@ -1149,12 +1154,12 @@ pub(crate) fn format_trait(
11491154 let open_pos = snippet. find_uncommented ( "{" ) ? + 1 ;
11501155 let outer_indent_str = offset. block_only ( ) . to_string_with_newline ( context. config ) ;
11511156
1152- if !trait_items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1157+ if !items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
11531158 let mut visitor = FmtVisitor :: from_context ( context) ;
11541159 visitor. block_indent = offset. block_only ( ) . block_indent ( context. config ) ;
11551160 visitor. last_pos = block_span. lo ( ) + BytePos ( open_pos as u32 ) ;
11561161
1157- for item in trait_items {
1162+ for item in items {
11581163 visitor. visit_trait_item ( item) ;
11591164 }
11601165
@@ -3125,17 +3130,22 @@ impl Rewrite for ast::ForeignItem {
31253130
31263131 let item_str = match self . kind {
31273132 ast:: ForeignItemKind :: Fn ( ref fn_kind) => {
3128- let ast:: FnKind ( defaultness, ref fn_sig, ref generics, ref block) = * * fn_kind;
3129- if let Some ( ref body) = block {
3133+ let ast:: Fn {
3134+ defaultness,
3135+ ref sig,
3136+ ref generics,
3137+ ref body,
3138+ } = * * fn_kind;
3139+ if let Some ( ref body) = body {
31303140 let mut visitor = FmtVisitor :: from_context ( context) ;
31313141 visitor. block_indent = shape. indent ;
31323142 visitor. last_pos = self . span . lo ( ) ;
31333143 let inner_attrs = inner_attributes ( & self . attrs ) ;
31343144 let fn_ctxt = visit:: FnCtxt :: Foreign ;
31353145 visitor. visit_fn (
3136- visit:: FnKind :: Fn ( fn_ctxt, self . ident , & fn_sig , & self . vis , Some ( body) ) ,
3146+ visit:: FnKind :: Fn ( fn_ctxt, self . ident , & sig , & self . vis , Some ( body) ) ,
31373147 generics,
3138- & fn_sig . decl ,
3148+ & sig . decl ,
31393149 self . span ,
31403150 defaultness,
31413151 Some ( & inner_attrs) ,
@@ -3146,7 +3156,7 @@ impl Rewrite for ast::ForeignItem {
31463156 context,
31473157 shape. indent ,
31483158 self . ident ,
3149- & FnSig :: from_method_sig ( & fn_sig , generics, & self . vis ) ,
3159+ & FnSig :: from_method_sig ( & sig , generics, & self . vis ) ,
31503160 span,
31513161 FnBraceStyle :: None ,
31523162 )
@@ -3168,16 +3178,20 @@ impl Rewrite for ast::ForeignItem {
31683178 rewrite_assign_rhs ( context, prefix, & * * ty, shape. sub_width ( 1 ) ?) . map ( |s| s + ";" )
31693179 }
31703180 ast:: ForeignItemKind :: TyAlias ( ref ty_alias_kind) => {
3171- let ast:: TyAliasKind ( _, ref generics, ref generic_bounds, ref type_default) =
3172- * * ty_alias_kind;
3181+ let ast:: TyAlias {
3182+ ref generics,
3183+ ref bounds,
3184+ ref ty,
3185+ ..
3186+ } = * * ty_alias_kind;
31733187 rewrite_type (
31743188 & context,
31753189 shape. indent ,
31763190 self . ident ,
31773191 & self . vis ,
31783192 generics,
3179- Some ( generic_bounds ) ,
3180- type_default . as_ref ( ) ,
3193+ Some ( bounds ) ,
3194+ ty . as_ref ( ) ,
31813195 self . span ,
31823196 )
31833197 }
0 commit comments