@@ -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 (
@@ -1133,7 +1138,7 @@ pub(crate) fn format_trait(
1133
1138
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1134
1139
}
1135
1140
_ if context. config . empty_item_single_line ( )
1136
- && trait_items . is_empty ( )
1141
+ && items . is_empty ( )
1137
1142
&& !result. contains ( '\n' )
1138
1143
&& !contains_comment ( & snippet[ open_pos..] ) =>
1139
1144
{
@@ -1146,7 +1151,7 @@ pub(crate) fn format_trait(
1146
1151
BraceStyle :: PreferSameLine => result. push ( ' ' ) ,
1147
1152
BraceStyle :: SameLineWhere => {
1148
1153
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 ( ) )
1150
1155
{
1151
1156
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1152
1157
} else {
@@ -1158,12 +1163,12 @@ pub(crate) fn format_trait(
1158
1163
1159
1164
let outer_indent_str = offset. block_only ( ) . to_string_with_newline ( context. config ) ;
1160
1165
1161
- if !trait_items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1166
+ if !items . is_empty ( ) || contains_comment ( & snippet[ open_pos..] ) {
1162
1167
let mut visitor = FmtVisitor :: from_context ( context) ;
1163
1168
visitor. block_indent = offset. block_only ( ) . block_indent ( context. config ) ;
1164
1169
visitor. last_pos = block_span. lo ( ) + BytePos ( open_pos as u32 ) ;
1165
1170
1166
- for item in trait_items {
1171
+ for item in items {
1167
1172
visitor. visit_trait_item ( item) ;
1168
1173
}
1169
1174
@@ -1522,15 +1527,20 @@ struct TyAliasRewriteInfo<'c, 'g>(
1522
1527
) ;
1523
1528
1524
1529
pub ( crate ) fn rewrite_type_alias < ' a , ' b > (
1525
- ty_alias_kind : & ast:: TyAliasKind ,
1530
+ ty_alias_kind : & ast:: TyAlias ,
1526
1531
context : & RewriteContext < ' a > ,
1527
1532
indent : Indent ,
1528
1533
visitor_kind : & ItemVisitorKind < ' b > ,
1529
1534
span : Span ,
1530
1535
) -> Option < String > {
1531
1536
use ItemVisitorKind :: * ;
1532
1537
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;
1534
1544
let ty_opt = ty. as_ref ( ) . map ( |t| & * * t) ;
1535
1545
let ( ident, vis) = match visitor_kind {
1536
1546
Item ( i) => ( i. ident , & i. vis ) ,
@@ -1545,17 +1555,17 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
1545
1555
// https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/items.md#type-aliases
1546
1556
match ( visitor_kind, ty_opt) {
1547
1557
( 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)
1550
1560
}
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) ,
1552
1562
( AssocImplItem ( _) , _) => {
1553
1563
let result = if let Some ( ast:: Ty {
1554
- kind : ast:: TyKind :: ImplTrait ( _, ref generic_bounds ) ,
1564
+ kind : ast:: TyKind :: ImplTrait ( _, ref bounds ) ,
1555
1565
..
1556
1566
} ) = ty_opt
1557
1567
{
1558
- let op_ty = OpaqueType { generic_bounds } ;
1568
+ let op_ty = OpaqueType { bounds } ;
1559
1569
rewrite_ty ( rw_info, None , Some ( & op_ty) , & DEFAULT_VISIBILITY )
1560
1570
} else {
1561
1571
rewrite_ty ( rw_info, None , ty. as_ref ( ) , vis)
@@ -1566,7 +1576,7 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
1566
1576
}
1567
1577
}
1568
1578
( 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)
1570
1580
}
1571
1581
}
1572
1582
}
@@ -1891,13 +1901,13 @@ fn rewrite_static(
1891
1901
}
1892
1902
}
1893
1903
struct OpaqueType < ' a > {
1894
- generic_bounds : & ' a ast:: GenericBounds ,
1904
+ bounds : & ' a ast:: GenericBounds ,
1895
1905
}
1896
1906
1897
1907
impl < ' a > Rewrite for OpaqueType < ' a > {
1898
1908
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1899
1909
let shape = shape. offset_left ( 5 ) ?; // `impl `
1900
- self . generic_bounds
1910
+ self . bounds
1901
1911
. rewrite ( context, shape)
1902
1912
. map ( |s| format ! ( "impl {}" , s) )
1903
1913
}
@@ -3126,17 +3136,22 @@ impl Rewrite for ast::ForeignItem {
3126
3136
3127
3137
let item_str = match self . kind {
3128
3138
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 {
3131
3146
let mut visitor = FmtVisitor :: from_context ( context) ;
3132
3147
visitor. block_indent = shape. indent ;
3133
3148
visitor. last_pos = self . span . lo ( ) ;
3134
3149
let inner_attrs = inner_attributes ( & self . attrs ) ;
3135
3150
let fn_ctxt = visit:: FnCtxt :: Foreign ;
3136
3151
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) ) ,
3138
3153
generics,
3139
- & fn_sig . decl ,
3154
+ & sig . decl ,
3140
3155
self . span ,
3141
3156
defaultness,
3142
3157
Some ( & inner_attrs) ,
@@ -3147,7 +3162,7 @@ impl Rewrite for ast::ForeignItem {
3147
3162
context,
3148
3163
shape. indent ,
3149
3164
self . ident ,
3150
- & FnSig :: from_method_sig ( fn_sig , generics, & self . vis ) ,
3165
+ & FnSig :: from_method_sig ( & sig , generics, & self . vis ) ,
3151
3166
span,
3152
3167
FnBraceStyle :: None ,
3153
3168
)
0 commit comments