@@ -712,8 +712,8 @@ impl<'a> FmtVisitor<'a> {
712
712
use ast:: AssocItemKind :: * ;
713
713
fn need_empty_line ( a : & ast:: AssocItemKind , b : & ast:: AssocItemKind ) -> bool {
714
714
match ( a, b) {
715
- ( TyAlias ( _ , _ , _ , ref lty) , TyAlias ( _ , _ , _ , ref rty) )
716
- if both_type ( lty, rty) || both_opaque ( lty, rty) =>
715
+ ( TyAlias ( lty) , TyAlias ( rty) )
716
+ if both_type ( & lty. 3 , & rty. 3 ) || both_opaque ( & lty. 3 , & rty. 3 ) =>
717
717
{
718
718
false
719
719
}
@@ -723,17 +723,17 @@ impl<'a> FmtVisitor<'a> {
723
723
}
724
724
725
725
buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. kind , & b. kind ) {
726
- ( TyAlias ( _ , _ , _ , ref lty) , TyAlias ( _ , _ , _ , ref rty) )
727
- if both_type ( lty, rty) || both_opaque ( lty, rty) =>
726
+ ( TyAlias ( lty) , TyAlias ( rty) )
727
+ if both_type ( & lty. 3 , & rty. 3 ) || both_opaque ( & lty. 3 , & rty. 3 ) =>
728
728
{
729
729
compare_as_versions ( & a. ident . as_str ( ) , & b. ident . as_str ( ) )
730
730
}
731
731
( Const ( ..) , Const ( ..) ) | ( MacCall ( ..) , MacCall ( ..) ) => {
732
732
compare_as_versions ( & a. ident . as_str ( ) , & b. ident . as_str ( ) )
733
733
}
734
734
( Fn ( ..) , Fn ( ..) ) => a. span . lo ( ) . cmp ( & b. span . lo ( ) ) ,
735
- ( TyAlias ( _ , _ , _ , ref ty) , _) if is_type ( ty ) => Ordering :: Less ,
736
- ( _, TyAlias ( _ , _ , _ , ref ty) ) if is_type ( ty ) => Ordering :: Greater ,
735
+ ( TyAlias ( ty) , _) if is_type ( & ty . 3 ) => Ordering :: Less ,
736
+ ( _, TyAlias ( ty) ) if is_type ( & ty . 3 ) => Ordering :: Greater ,
737
737
( TyAlias ( ..) , _) => Ordering :: Less ,
738
738
( _, TyAlias ( ..) ) => Ordering :: Greater ,
739
739
( Const ( ..) , _) => Ordering :: Less ,
@@ -769,13 +769,13 @@ pub(crate) fn format_impl(
769
769
item : & ast:: Item ,
770
770
offset : Indent ,
771
771
) -> Option < String > {
772
- if let ast:: ItemKind :: Impl {
773
- ref generics ,
774
- ref self_ty ,
775
- ref items ,
776
- ..
777
- } = item . kind
778
- {
772
+ if let ast:: ItemKind :: Impl ( impl_kind ) = & item . kind {
773
+ let ast :: ImplKind {
774
+ ref generics ,
775
+ ref self_ty ,
776
+ ref items ,
777
+ ..
778
+ } = * * impl_kind ;
779
779
let mut result = String :: with_capacity ( 128 ) ;
780
780
let ref_and_type = format_impl_ref_and_type ( context, item, offset) ?;
781
781
let sep = offset. to_string_with_newline ( context. config ) ;
@@ -931,17 +931,17 @@ fn format_impl_ref_and_type(
931
931
item : & ast:: Item ,
932
932
offset : Indent ,
933
933
) -> Option < String > {
934
- if let ast:: ItemKind :: Impl {
935
- unsafety ,
936
- polarity ,
937
- defaultness ,
938
- constness ,
939
- ref generics ,
940
- of_trait : ref trait_ref ,
941
- ref self_ty ,
942
- ..
943
- } = item . kind
944
- {
934
+ if let ast:: ItemKind :: Impl ( impl_kind ) = & item . kind {
935
+ let ast :: ImplKind {
936
+ unsafety ,
937
+ polarity ,
938
+ defaultness ,
939
+ constness ,
940
+ ref generics ,
941
+ of_trait : ref trait_ref ,
942
+ ref self_ty ,
943
+ ..
944
+ } = * * impl_kind ;
945
945
let mut result = String :: with_capacity ( 128 ) ;
946
946
947
947
result. push_str ( & format_visibility ( context, & item. vis ) ) ;
@@ -1119,14 +1119,9 @@ pub(crate) fn format_trait(
1119
1119
item : & ast:: Item ,
1120
1120
offset : Indent ,
1121
1121
) -> Option < String > {
1122
- if let ast:: ItemKind :: Trait (
1123
- is_auto,
1124
- unsafety,
1125
- ref generics,
1126
- ref generic_bounds,
1127
- ref trait_items,
1128
- ) = item. kind
1129
- {
1122
+ if let ast:: ItemKind :: Trait ( trait_kind) = & item. kind {
1123
+ let ast:: TraitKind ( is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
1124
+ * * trait_kind;
1130
1125
let mut result = String :: with_capacity ( 128 ) ;
1131
1126
let header = format ! (
1132
1127
"{}{}{}trait " ,
@@ -3256,31 +3251,35 @@ impl Rewrite for ast::ForeignItem {
3256
3251
let span = mk_sp ( self . span . lo ( ) , self . span . hi ( ) - BytePos ( 1 ) ) ;
3257
3252
3258
3253
let item_str = match self . kind {
3259
- ast:: ForeignItemKind :: Fn ( defaultness, ref fn_sig, ref generics, Some ( ref body) ) => {
3260
- let mut visitor = FmtVisitor :: from_context ( context) ;
3261
- visitor. block_indent = shape. indent ;
3262
- visitor. last_pos = self . span . lo ( ) ;
3263
- let inner_attrs = inner_attributes ( & self . attrs ) ;
3264
- let fn_ctxt = visit:: FnCtxt :: Foreign ;
3265
- visitor. visit_fn (
3266
- visit:: FnKind :: Fn ( fn_ctxt, self . ident , & fn_sig, & self . vis , Some ( body) ) ,
3267
- generics,
3268
- & fn_sig. decl ,
3269
- self . span ,
3270
- defaultness,
3271
- Some ( & inner_attrs) ,
3272
- ) ;
3273
- Some ( visitor. buffer . to_owned ( ) )
3254
+ ast:: ForeignItemKind :: Fn ( ref fn_kind) => {
3255
+ let ast:: FnKind ( defaultness, ref fn_sig, ref generics, ref block) = * * fn_kind;
3256
+ if let Some ( ref body) = block {
3257
+ let mut visitor = FmtVisitor :: from_context ( context) ;
3258
+ visitor. block_indent = shape. indent ;
3259
+ visitor. last_pos = self . span . lo ( ) ;
3260
+ let inner_attrs = inner_attributes ( & self . attrs ) ;
3261
+ let fn_ctxt = visit:: FnCtxt :: Foreign ;
3262
+ visitor. visit_fn (
3263
+ visit:: FnKind :: Fn ( fn_ctxt, self . ident , & fn_sig, & self . vis , Some ( body) ) ,
3264
+ generics,
3265
+ & fn_sig. decl ,
3266
+ self . span ,
3267
+ defaultness,
3268
+ Some ( & inner_attrs) ,
3269
+ ) ;
3270
+ Some ( visitor. buffer . to_owned ( ) )
3271
+ } else {
3272
+ rewrite_fn_base (
3273
+ context,
3274
+ shape. indent ,
3275
+ self . ident ,
3276
+ & FnSig :: from_method_sig ( & fn_sig, generics, self . vis . clone ( ) ) ,
3277
+ span,
3278
+ FnBraceStyle :: None ,
3279
+ )
3280
+ . map ( |( s, _, _) | format ! ( "{};" , s) )
3281
+ }
3274
3282
}
3275
- ast:: ForeignItemKind :: Fn ( _, ref fn_sig, ref generics, None ) => rewrite_fn_base (
3276
- context,
3277
- shape. indent ,
3278
- self . ident ,
3279
- & FnSig :: from_method_sig ( & fn_sig, generics, self . vis . clone ( ) ) ,
3280
- span,
3281
- FnBraceStyle :: None ,
3282
- )
3283
- . map ( |( s, _, _) | format ! ( "{};" , s) ) ,
3284
3283
ast:: ForeignItemKind :: Static ( ref ty, mutability, _) => {
3285
3284
// FIXME(#21): we're dropping potential comments in between the
3286
3285
// function kw here.
@@ -3295,21 +3294,20 @@ impl Rewrite for ast::ForeignItem {
3295
3294
// 1 = ;
3296
3295
rewrite_assign_rhs ( context, prefix, & * * ty, shape. sub_width ( 1 ) ?) . map ( |s| s + ";" )
3297
3296
}
3298
- ast:: ForeignItemKind :: TyAlias (
3299
- _,
3300
- ref generics,
3301
- ref generic_bounds,
3302
- ref type_default,
3303
- ) => rewrite_type_alias (
3304
- self . ident ,
3305
- type_default. as_ref ( ) ,
3306
- generics,
3307
- Some ( generic_bounds) ,
3308
- & context,
3309
- shape. indent ,
3310
- & self . vis ,
3311
- self . span ,
3312
- ) ,
3297
+ ast:: ForeignItemKind :: TyAlias ( ref ty_alias_kind) => {
3298
+ let ast:: TyAliasKind ( _, ref generics, ref generic_bounds, ref type_default) =
3299
+ * * ty_alias_kind;
3300
+ rewrite_type_alias (
3301
+ self . ident ,
3302
+ type_default. as_ref ( ) ,
3303
+ generics,
3304
+ Some ( generic_bounds) ,
3305
+ & context,
3306
+ shape. indent ,
3307
+ & self . vis ,
3308
+ self . span ,
3309
+ )
3310
+ }
3313
3311
ast:: ForeignItemKind :: MacCall ( ref mac) => {
3314
3312
rewrite_macro ( mac, None , context, shape, MacroPosition :: Item )
3315
3313
}
0 commit comments