@@ -333,12 +333,12 @@ impl<'a> FnSig<'a> {
333333 defaultness : ast:: Defaultness ,
334334 ) -> FnSig < ' a > {
335335 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, .. } ) => {
337337 let mut fn_sig = FnSig :: from_method_sig ( sig, generics, vis) ;
338338 fn_sig. defaultness = defaultness;
339339 fn_sig
340340 }
341- visit:: FnKind :: Fn ( _, _ , vis, ast:: Fn { sig, generics, .. } ) => FnSig {
341+ visit:: FnKind :: Fn ( _, vis, ast:: Fn { sig, generics, .. } ) => FnSig {
342342 decl,
343343 generics,
344344 ext : sig. header . ext ,
@@ -750,11 +750,10 @@ impl<'a> FmtVisitor<'a> {
750750 ( Type ( lty) , Type ( rty) )
751751 if both_type ( & lty. ty , & rty. ty ) || both_opaque ( & lty. ty , & rty. ty ) =>
752752 {
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 ( ) )
757754 }
755+ ( Const ( ca) , Const ( cb) ) => ca. ident . as_str ( ) . cmp ( cb. ident . as_str ( ) ) ,
756+ ( MacCall ( ..) , MacCall ( ..) ) => Ordering :: Equal ,
758757 ( Fn ( ..) , Fn ( ..) ) | ( Delegation ( ..) , Delegation ( ..) ) => {
759758 a. span . lo ( ) . cmp ( & b. span . lo ( ) )
760759 }
@@ -1105,14 +1104,16 @@ impl<'a> StructParts<'a> {
11051104 }
11061105
11071106 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) ,
11111112 _ => unreachable ! ( ) ,
11121113 } ;
11131114 StructParts {
11141115 prefix,
1115- ident : item . ident ,
1116+ ident,
11161117 vis : & item. vis ,
11171118 def,
11181119 generics : Some ( generics) ,
@@ -1168,6 +1169,7 @@ pub(crate) fn format_trait(
11681169 let ast:: Trait {
11691170 is_auto,
11701171 safety,
1172+ ident,
11711173 ref generics,
11721174 ref bounds,
11731175 ref items,
@@ -1186,13 +1188,13 @@ pub(crate) fn format_trait(
11861188
11871189 let shape = Shape :: indented ( offset, context. config ) . offset_left ( result. len ( ) ) ?;
11881190 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 ( ) ?;
11901192 result. push_str ( & generics_str) ;
11911193
11921194 // FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
11931195 if !bounds. is_empty ( ) {
11941196 // Retrieve *unnormalized* ident (See #6069)
1195- let source_ident = context. snippet ( item . ident . span ) ;
1197+ let source_ident = context. snippet ( ident. span ) ;
11961198 let ident_hi = context. snippet_provider . span_after ( item. span , source_ident) ;
11971199 let bound_hi = bounds. last ( ) . unwrap ( ) . span ( ) . hi ( ) ;
11981200 let snippet = context. snippet ( mk_sp ( ident_hi, bound_hi) ) ;
@@ -1699,7 +1701,6 @@ struct TyAliasRewriteInfo<'c, 'g>(
16991701pub ( crate ) fn rewrite_type_alias < ' a > (
17001702 ty_alias_kind : & ast:: TyAlias ,
17011703 vis : & ast:: Visibility ,
1702- ident : Ident ,
17031704 context : & RewriteContext < ' a > ,
17041705 indent : Indent ,
17051706 visitor_kind : ItemVisitorKind ,
@@ -1709,6 +1710,7 @@ pub(crate) fn rewrite_type_alias<'a>(
17091710
17101711 let ast:: TyAlias {
17111712 defaultness,
1713+ ident,
17121714 ref generics,
17131715 ref bounds,
17141716 ref ty,
@@ -2022,14 +2024,23 @@ pub(crate) struct StaticParts<'a> {
20222024
20232025impl < ' a > StaticParts < ' a > {
20242026 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+ ) ,
20292039 ast:: ItemKind :: Const ( c) => (
20302040 Some ( c. defaultness ) ,
20312041 "const" ,
20322042 ast:: Safety :: Default ,
2043+ c. ident ,
20332044 & c. ty ,
20342045 ast:: Mutability :: Not ,
20352046 & c. expr ,
@@ -2041,7 +2052,7 @@ impl<'a> StaticParts<'a> {
20412052 prefix,
20422053 safety,
20432054 vis : & item. vis ,
2044- ident : item . ident ,
2055+ ident,
20452056 generics,
20462057 ty,
20472058 mutability,
@@ -2051,7 +2062,7 @@ impl<'a> StaticParts<'a> {
20512062 }
20522063 }
20532064
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 {
20552066 let ( defaultness, ty, expr_opt, generics) = match & ti. kind {
20562067 ast:: AssocItemKind :: Const ( c) => ( c. defaultness , & c. ty , & c. expr , Some ( & c. generics ) ) ,
20572068 _ => unreachable ! ( ) ,
@@ -2060,7 +2071,7 @@ impl<'a> StaticParts<'a> {
20602071 prefix : "const" ,
20612072 safety : ast:: Safety :: Default ,
20622073 vis : & ti. vis ,
2063- ident : ti . ident ,
2074+ ident,
20642075 generics,
20652076 ty,
20662077 mutability : ast:: Mutability :: Not ,
@@ -2070,7 +2081,7 @@ impl<'a> StaticParts<'a> {
20702081 }
20712082 }
20722083
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 {
20742085 let ( defaultness, ty, expr, generics) = match & ii. kind {
20752086 ast:: AssocItemKind :: Const ( c) => ( c. defaultness , & c. ty , & c. expr , Some ( & c. generics ) ) ,
20762087 _ => unreachable ! ( ) ,
@@ -2079,7 +2090,7 @@ impl<'a> StaticParts<'a> {
20792090 prefix : "const" ,
20802091 safety : ast:: Safety :: Default ,
20812092 vis : & ii. vis ,
2082- ident : ii . ident ,
2093+ ident,
20832094 generics,
20842095 ty,
20852096 mutability : ast:: Mutability :: Not ,
@@ -3440,6 +3451,7 @@ impl Rewrite for ast::ForeignItem {
34403451 let ast:: Fn {
34413452 defaultness,
34423453 ref sig,
3454+ ident,
34433455 ref generics,
34443456 ref body,
34453457 ..
@@ -3451,7 +3463,8 @@ impl Rewrite for ast::ForeignItem {
34513463 let inner_attrs = inner_attributes ( & self . attrs ) ;
34523464 let fn_ctxt = visit:: FnCtxt :: Foreign ;
34533465 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) ,
34553468 & sig. decl ,
34563469 self . span ,
34573470 defaultness,
@@ -3462,7 +3475,7 @@ impl Rewrite for ast::ForeignItem {
34623475 rewrite_fn_base (
34633476 context,
34643477 shape. indent ,
3465- self . ident ,
3478+ ident,
34663479 & FnSig :: from_method_sig ( sig, generics, & self . vis ) ,
34673480 span,
34683481 FnBraceStyle :: None ,
@@ -3481,7 +3494,7 @@ impl Rewrite for ast::ForeignItem {
34813494 vis,
34823495 safety,
34833496 mut_str,
3484- rewrite_ident( context, self . ident)
3497+ rewrite_ident( context, static_foreign_item . ident)
34853498 ) ;
34863499 // 1 = ;
34873500 rewrite_assign_rhs (
@@ -3497,15 +3510,7 @@ impl Rewrite for ast::ForeignItem {
34973510 }
34983511 ast:: ForeignItemKind :: TyAlias ( ref ty_alias) => {
34993512 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 )
35093514 }
35103515 ast:: ForeignItemKind :: MacCall ( ref mac) => {
35113516 rewrite_macro ( mac, context, shape, MacroPosition :: Item )
@@ -3568,12 +3573,13 @@ fn rewrite_attrs(
35683573pub ( crate ) fn rewrite_mod (
35693574 context : & RewriteContext < ' _ > ,
35703575 item : & ast:: Item ,
3576+ ident : Ident ,
35713577 attrs_shape : Shape ,
35723578) -> Option < String > {
35733579 let mut result = String :: with_capacity ( 32 ) ;
35743580 result. push_str ( & * format_visibility ( context, & item. vis ) ) ;
35753581 result. push_str ( "mod " ) ;
3576- result. push_str ( rewrite_ident ( context, item . ident ) ) ;
3582+ result. push_str ( rewrite_ident ( context, ident) ) ;
35773583 result. push ( ';' ) ;
35783584 rewrite_attrs ( context, item, & result, attrs_shape)
35793585}
@@ -3600,7 +3606,7 @@ pub(crate) fn rewrite_extern_crate(
36003606pub ( crate ) fn is_mod_decl ( item : & ast:: Item ) -> bool {
36013607 !matches ! (
36023608 item. kind,
3603- ast:: ItemKind :: Mod ( _, ast:: ModKind :: Loaded ( _, ast:: Inline :: Yes , _, _) )
3609+ ast:: ItemKind :: Mod ( _, _ , ast:: ModKind :: Loaded ( _, ast:: Inline :: Yes , _, _) )
36043610 )
36053611}
36063612
0 commit comments