@@ -622,7 +622,7 @@ impl<'a> FmtVisitor<'a> {
622
622
fn need_empty_line ( a : & ast:: AssocItemKind , b : & ast:: AssocItemKind ) -> bool {
623
623
match ( a, b) {
624
624
( 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 ) =>
626
626
{
627
627
false
628
628
}
@@ -633,16 +633,16 @@ impl<'a> FmtVisitor<'a> {
633
633
634
634
buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. kind , & b. kind ) {
635
635
( 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 ) =>
637
637
{
638
638
a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
639
639
}
640
640
( Const ( ..) , Const ( ..) ) | ( MacCall ( ..) , MacCall ( ..) ) => {
641
641
a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
642
642
}
643
643
( 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 ,
646
646
( TyAlias ( ..) , _) => Ordering :: Less ,
647
647
( _, TyAlias ( ..) ) => Ordering :: Greater ,
648
648
( Const ( ..) , _) => Ordering :: Less ,
@@ -679,7 +679,7 @@ pub(crate) fn format_impl(
679
679
offset : Indent ,
680
680
) -> Option < String > {
681
681
if let ast:: ItemKind :: Impl ( impl_kind) = & item. kind {
682
- let ast:: ImplKind {
682
+ let ast:: Impl {
683
683
ref generics,
684
684
ref self_ty,
685
685
ref items,
@@ -833,7 +833,7 @@ fn format_impl_ref_and_type(
833
833
offset : Indent ,
834
834
) -> Option < String > {
835
835
if let ast:: ItemKind :: Impl ( impl_kind) = & item. kind {
836
- let ast:: ImplKind {
836
+ let ast:: Impl {
837
837
unsafety,
838
838
polarity,
839
839
defaultness,
@@ -1029,8 +1029,13 @@ pub(crate) fn format_trait(
1029
1029
offset : Indent ,
1030
1030
) -> Option < String > {
1031
1031
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;
1034
1039
let mut result = String :: with_capacity ( 128 ) ;
1035
1040
let header = format ! (
1036
1041
"{}{}{}trait " ,
@@ -1048,11 +1053,11 @@ pub(crate) fn format_trait(
1048
1053
result. push_str ( & generics_str) ;
1049
1054
1050
1055
// FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
1051
- if !generic_bounds . is_empty ( ) {
1056
+ if !bounds . is_empty ( ) {
1052
1057
let ident_hi = context
1053
1058
. snippet_provider
1054
1059
. 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 ( ) ;
1056
1061
let snippet = context. snippet ( mk_sp ( ident_hi, bound_hi) ) ;
1057
1062
if contains_comment ( snippet) {
1058
1063
return None ;
@@ -1061,7 +1066,7 @@ pub(crate) fn format_trait(
1061
1066
result = rewrite_assign_rhs_with (
1062
1067
context,
1063
1068
result + ":" ,
1064
- generic_bounds ,
1069
+ bounds ,
1065
1070
shape,
1066
1071
RhsTactics :: ForceNextLineWithoutIndent ,
1067
1072
) ?;
@@ -1072,10 +1077,10 @@ pub(crate) fn format_trait(
1072
1077
let where_on_new_line = context. config . indent_style ( ) != IndentStyle :: Block ;
1073
1078
1074
1079
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 ( ) {
1076
1081
generics. where_clause . span . lo ( )
1077
1082
} else {
1078
- generic_bounds [ generic_bounds . len ( ) - 1 ] . span ( ) . hi ( )
1083
+ bounds [ bounds . len ( ) - 1 ] . span ( ) . hi ( )
1079
1084
} ;
1080
1085
let option = WhereClauseOption :: snuggled ( & generics_str) ;
1081
1086
let where_clause_str = rewrite_where_clause (
@@ -1134,7 +1139,7 @@ pub(crate) fn format_trait(
1134
1139
BraceStyle :: PreferSameLine => result. push ( ' ' ) ,
1135
1140
BraceStyle :: SameLineWhere => {
1136
1141
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 ( ) )
1138
1143
{
1139
1144
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1140
1145
} else {
@@ -1149,12 +1154,12 @@ pub(crate) fn format_trait(
1149
1154
let open_pos = snippet. find_uncommented ( "{" ) ? + 1 ;
1150
1155
let outer_indent_str = offset. block_only ( ) . to_string_with_newline ( context. config ) ;
1151
1156
1152
- if !trait_items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1157
+ if !items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1153
1158
let mut visitor = FmtVisitor :: from_context ( context) ;
1154
1159
visitor. block_indent = offset. block_only ( ) . block_indent ( context. config ) ;
1155
1160
visitor. last_pos = block_span. lo ( ) + BytePos ( open_pos as u32 ) ;
1156
1161
1157
- for item in trait_items {
1162
+ for item in items {
1158
1163
visitor. visit_trait_item ( item) ;
1159
1164
}
1160
1165
@@ -3125,17 +3130,22 @@ impl Rewrite for ast::ForeignItem {
3125
3130
3126
3131
let item_str = match self . kind {
3127
3132
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 {
3130
3140
let mut visitor = FmtVisitor :: from_context ( context) ;
3131
3141
visitor. block_indent = shape. indent ;
3132
3142
visitor. last_pos = self . span . lo ( ) ;
3133
3143
let inner_attrs = inner_attributes ( & self . attrs ) ;
3134
3144
let fn_ctxt = visit:: FnCtxt :: Foreign ;
3135
3145
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) ) ,
3137
3147
generics,
3138
- & fn_sig . decl ,
3148
+ & sig . decl ,
3139
3149
self . span ,
3140
3150
defaultness,
3141
3151
Some ( & inner_attrs) ,
@@ -3146,7 +3156,7 @@ impl Rewrite for ast::ForeignItem {
3146
3156
context,
3147
3157
shape. indent ,
3148
3158
self . ident ,
3149
- & FnSig :: from_method_sig ( & fn_sig , generics, & self . vis ) ,
3159
+ & FnSig :: from_method_sig ( & sig , generics, & self . vis ) ,
3150
3160
span,
3151
3161
FnBraceStyle :: None ,
3152
3162
)
@@ -3168,16 +3178,20 @@ impl Rewrite for ast::ForeignItem {
3168
3178
rewrite_assign_rhs ( context, prefix, & * * ty, shape. sub_width ( 1 ) ?) . map ( |s| s + ";" )
3169
3179
}
3170
3180
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;
3173
3187
rewrite_type (
3174
3188
& context,
3175
3189
shape. indent ,
3176
3190
self . ident ,
3177
3191
& self . vis ,
3178
3192
generics,
3179
- Some ( generic_bounds ) ,
3180
- type_default . as_ref ( ) ,
3193
+ Some ( bounds ) ,
3194
+ ty . as_ref ( ) ,
3181
3195
self . span ,
3182
3196
)
3183
3197
}
0 commit comments