@@ -333,12 +333,12 @@ impl<'a> FnSig<'a> {
333
333
defaultness : ast:: Defaultness ,
334
334
) -> FnSig < ' a > {
335
335
match * fn_kind {
336
- visit:: FnKind :: Fn ( visit:: FnCtxt :: Assoc ( ..) , _ , vis, ast:: Fn { sig, generics, .. } ) => {
336
+ visit:: FnKind :: Fn ( visit:: FnCtxt :: Assoc ( ..) , vis, ast:: Fn { sig, generics, .. } ) => {
337
337
let mut fn_sig = FnSig :: from_method_sig ( sig, generics, vis) ;
338
338
fn_sig. defaultness = defaultness;
339
339
fn_sig
340
340
}
341
- visit:: FnKind :: Fn ( _, _ , vis, ast:: Fn { sig, generics, .. } ) => FnSig {
341
+ visit:: FnKind :: Fn ( _, vis, ast:: Fn { sig, generics, .. } ) => FnSig {
342
342
decl,
343
343
generics,
344
344
ext : sig. header . ext ,
@@ -750,11 +750,10 @@ impl<'a> FmtVisitor<'a> {
750
750
( Type ( lty) , Type ( rty) )
751
751
if both_type ( & lty. ty , & rty. ty ) || both_opaque ( & lty. ty , & rty. ty ) =>
752
752
{
753
- a. ident . as_str ( ) . cmp ( b. ident . as_str ( ) )
754
- }
755
- ( Const ( ..) , Const ( ..) ) | ( MacCall ( ..) , MacCall ( ..) ) => {
756
- a. ident . as_str ( ) . cmp ( b. ident . as_str ( ) )
753
+ lty. ident . as_str ( ) . cmp ( rty. ident . as_str ( ) )
757
754
}
755
+ ( Const ( ca) , Const ( cb) ) => ca. ident . as_str ( ) . cmp ( cb. ident . as_str ( ) ) ,
756
+ ( MacCall ( ..) , MacCall ( ..) ) => Ordering :: Equal ,
758
757
( Fn ( ..) , Fn ( ..) ) | ( Delegation ( ..) , Delegation ( ..) ) => {
759
758
a. span . lo ( ) . cmp ( & b. span . lo ( ) )
760
759
}
@@ -1105,14 +1104,16 @@ impl<'a> StructParts<'a> {
1105
1104
}
1106
1105
1107
1106
pub ( crate ) fn from_item ( item : & ' a ast:: Item ) -> Self {
1108
- let ( prefix, def, generics) = match item. kind {
1109
- ast:: ItemKind :: Struct ( ref def, ref generics) => ( "struct " , def, generics) ,
1110
- ast:: ItemKind :: Union ( ref def, ref generics) => ( "union " , def, generics) ,
1107
+ let ( prefix, def, ident, generics) = match item. kind {
1108
+ ast:: ItemKind :: Struct ( ident, ref def, ref generics) => {
1109
+ ( "struct " , def, ident, generics)
1110
+ }
1111
+ ast:: ItemKind :: Union ( ident, ref def, ref generics) => ( "union " , def, ident, generics) ,
1111
1112
_ => unreachable ! ( ) ,
1112
1113
} ;
1113
1114
StructParts {
1114
1115
prefix,
1115
- ident : item . ident ,
1116
+ ident,
1116
1117
vis : & item. vis ,
1117
1118
def,
1118
1119
generics : Some ( generics) ,
@@ -1168,6 +1169,7 @@ pub(crate) fn format_trait(
1168
1169
let ast:: Trait {
1169
1170
is_auto,
1170
1171
safety,
1172
+ ident,
1171
1173
ref generics,
1172
1174
ref bounds,
1173
1175
ref items,
@@ -1186,13 +1188,13 @@ pub(crate) fn format_trait(
1186
1188
1187
1189
let shape = Shape :: indented ( offset, context. config ) . offset_left ( result. len ( ) ) ?;
1188
1190
let generics_str =
1189
- rewrite_generics ( context, rewrite_ident ( context, item . ident ) , generics, shape) . ok ( ) ?;
1191
+ rewrite_generics ( context, rewrite_ident ( context, ident) , generics, shape) . ok ( ) ?;
1190
1192
result. push_str ( & generics_str) ;
1191
1193
1192
1194
// FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
1193
1195
if !bounds. is_empty ( ) {
1194
1196
// Retrieve *unnormalized* ident (See #6069)
1195
- let source_ident = context. snippet ( item . ident . span ) ;
1197
+ let source_ident = context. snippet ( ident. span ) ;
1196
1198
let ident_hi = context. snippet_provider . span_after ( item. span , source_ident) ;
1197
1199
let bound_hi = bounds. last ( ) . unwrap ( ) . span ( ) . hi ( ) ;
1198
1200
let snippet = context. snippet ( mk_sp ( ident_hi, bound_hi) ) ;
@@ -1699,7 +1701,6 @@ struct TyAliasRewriteInfo<'c, 'g>(
1699
1701
pub ( crate ) fn rewrite_type_alias < ' a > (
1700
1702
ty_alias_kind : & ast:: TyAlias ,
1701
1703
vis : & ast:: Visibility ,
1702
- ident : Ident ,
1703
1704
context : & RewriteContext < ' a > ,
1704
1705
indent : Indent ,
1705
1706
visitor_kind : ItemVisitorKind ,
@@ -1709,6 +1710,7 @@ pub(crate) fn rewrite_type_alias<'a>(
1709
1710
1710
1711
let ast:: TyAlias {
1711
1712
defaultness,
1713
+ ident,
1712
1714
ref generics,
1713
1715
ref bounds,
1714
1716
ref ty,
@@ -2022,14 +2024,23 @@ pub(crate) struct StaticParts<'a> {
2022
2024
2023
2025
impl < ' a > StaticParts < ' a > {
2024
2026
pub ( crate ) fn from_item ( item : & ' a ast:: Item ) -> Self {
2025
- let ( defaultness, prefix, safety, ty, mutability, expr, generics) = match & item. kind {
2026
- ast:: ItemKind :: Static ( s) => {
2027
- ( None , "static" , s. safety , & s. ty , s. mutability , & s. expr , None )
2028
- }
2027
+ let ( defaultness, prefix, safety, ident, ty, mutability, expr, generics) = match & item. kind
2028
+ {
2029
+ ast:: ItemKind :: Static ( s) => (
2030
+ None ,
2031
+ "static" ,
2032
+ s. safety ,
2033
+ s. ident ,
2034
+ & s. ty ,
2035
+ s. mutability ,
2036
+ & s. expr ,
2037
+ None ,
2038
+ ) ,
2029
2039
ast:: ItemKind :: Const ( c) => (
2030
2040
Some ( c. defaultness ) ,
2031
2041
"const" ,
2032
2042
ast:: Safety :: Default ,
2043
+ c. ident ,
2033
2044
& c. ty ,
2034
2045
ast:: Mutability :: Not ,
2035
2046
& c. expr ,
@@ -2041,7 +2052,7 @@ impl<'a> StaticParts<'a> {
2041
2052
prefix,
2042
2053
safety,
2043
2054
vis : & item. vis ,
2044
- ident : item . ident ,
2055
+ ident,
2045
2056
generics,
2046
2057
ty,
2047
2058
mutability,
@@ -2051,7 +2062,7 @@ impl<'a> StaticParts<'a> {
2051
2062
}
2052
2063
}
2053
2064
2054
- pub ( crate ) fn from_trait_item ( ti : & ' a ast:: AssocItem ) -> Self {
2065
+ pub ( crate ) fn from_trait_item ( ti : & ' a ast:: AssocItem , ident : Ident ) -> Self {
2055
2066
let ( defaultness, ty, expr_opt, generics) = match & ti. kind {
2056
2067
ast:: AssocItemKind :: Const ( c) => ( c. defaultness , & c. ty , & c. expr , Some ( & c. generics ) ) ,
2057
2068
_ => unreachable ! ( ) ,
@@ -2060,7 +2071,7 @@ impl<'a> StaticParts<'a> {
2060
2071
prefix : "const" ,
2061
2072
safety : ast:: Safety :: Default ,
2062
2073
vis : & ti. vis ,
2063
- ident : ti . ident ,
2074
+ ident,
2064
2075
generics,
2065
2076
ty,
2066
2077
mutability : ast:: Mutability :: Not ,
@@ -2070,7 +2081,7 @@ impl<'a> StaticParts<'a> {
2070
2081
}
2071
2082
}
2072
2083
2073
- pub ( crate ) fn from_impl_item ( ii : & ' a ast:: AssocItem ) -> Self {
2084
+ pub ( crate ) fn from_impl_item ( ii : & ' a ast:: AssocItem , ident : Ident ) -> Self {
2074
2085
let ( defaultness, ty, expr, generics) = match & ii. kind {
2075
2086
ast:: AssocItemKind :: Const ( c) => ( c. defaultness , & c. ty , & c. expr , Some ( & c. generics ) ) ,
2076
2087
_ => unreachable ! ( ) ,
@@ -2079,7 +2090,7 @@ impl<'a> StaticParts<'a> {
2079
2090
prefix : "const" ,
2080
2091
safety : ast:: Safety :: Default ,
2081
2092
vis : & ii. vis ,
2082
- ident : ii . ident ,
2093
+ ident,
2083
2094
generics,
2084
2095
ty,
2085
2096
mutability : ast:: Mutability :: Not ,
@@ -3440,6 +3451,7 @@ impl Rewrite for ast::ForeignItem {
3440
3451
let ast:: Fn {
3441
3452
defaultness,
3442
3453
ref sig,
3454
+ ident,
3443
3455
ref generics,
3444
3456
ref body,
3445
3457
..
@@ -3451,7 +3463,8 @@ impl Rewrite for ast::ForeignItem {
3451
3463
let inner_attrs = inner_attributes ( & self . attrs ) ;
3452
3464
let fn_ctxt = visit:: FnCtxt :: Foreign ;
3453
3465
visitor. visit_fn (
3454
- visit:: FnKind :: Fn ( fn_ctxt, & self . ident , & self . vis , fn_kind) ,
3466
+ ident,
3467
+ visit:: FnKind :: Fn ( fn_ctxt, & self . vis , fn_kind) ,
3455
3468
& sig. decl ,
3456
3469
self . span ,
3457
3470
defaultness,
@@ -3462,7 +3475,7 @@ impl Rewrite for ast::ForeignItem {
3462
3475
rewrite_fn_base (
3463
3476
context,
3464
3477
shape. indent ,
3465
- self . ident ,
3478
+ ident,
3466
3479
& FnSig :: from_method_sig ( sig, generics, & self . vis ) ,
3467
3480
span,
3468
3481
FnBraceStyle :: None ,
@@ -3481,7 +3494,7 @@ impl Rewrite for ast::ForeignItem {
3481
3494
vis,
3482
3495
safety,
3483
3496
mut_str,
3484
- rewrite_ident( context, self . ident)
3497
+ rewrite_ident( context, static_foreign_item . ident)
3485
3498
) ;
3486
3499
// 1 = ;
3487
3500
rewrite_assign_rhs (
@@ -3497,15 +3510,7 @@ impl Rewrite for ast::ForeignItem {
3497
3510
}
3498
3511
ast:: ForeignItemKind :: TyAlias ( ref ty_alias) => {
3499
3512
let kind = ItemVisitorKind :: ForeignItem ;
3500
- rewrite_type_alias (
3501
- ty_alias,
3502
- & self . vis ,
3503
- self . ident ,
3504
- context,
3505
- shape. indent ,
3506
- kind,
3507
- self . span ,
3508
- )
3513
+ rewrite_type_alias ( ty_alias, & self . vis , context, shape. indent , kind, self . span )
3509
3514
}
3510
3515
ast:: ForeignItemKind :: MacCall ( ref mac) => {
3511
3516
rewrite_macro ( mac, context, shape, MacroPosition :: Item )
@@ -3568,12 +3573,13 @@ fn rewrite_attrs(
3568
3573
pub ( crate ) fn rewrite_mod (
3569
3574
context : & RewriteContext < ' _ > ,
3570
3575
item : & ast:: Item ,
3576
+ ident : Ident ,
3571
3577
attrs_shape : Shape ,
3572
3578
) -> Option < String > {
3573
3579
let mut result = String :: with_capacity ( 32 ) ;
3574
3580
result. push_str ( & * format_visibility ( context, & item. vis ) ) ;
3575
3581
result. push_str ( "mod " ) ;
3576
- result. push_str ( rewrite_ident ( context, item . ident ) ) ;
3582
+ result. push_str ( rewrite_ident ( context, ident) ) ;
3577
3583
result. push ( ';' ) ;
3578
3584
rewrite_attrs ( context, item, & result, attrs_shape)
3579
3585
}
@@ -3600,7 +3606,7 @@ pub(crate) fn rewrite_extern_crate(
3600
3606
pub ( crate ) fn is_mod_decl ( item : & ast:: Item ) -> bool {
3601
3607
!matches ! (
3602
3608
item. kind,
3603
- ast:: ItemKind :: Mod ( _, ast:: ModKind :: Loaded ( _, ast:: Inline :: Yes , _, _) )
3609
+ ast:: ItemKind :: Mod ( _, _ , ast:: ModKind :: Loaded ( _, ast:: Inline :: Yes , _, _) )
3604
3610
)
3605
3611
}
3606
3612
0 commit comments