@@ -1023,17 +1023,8 @@ impl<'a> State<'a> {
10231023 ast:: ForeignItemKind :: Fn ( sig, gen, body) => {
10241024 self . print_fn_full ( sig, item. ident , gen, & item. vis , body. as_deref ( ) , & item. attrs ) ;
10251025 }
1026- ast:: ForeignItemKind :: Static ( t, m) => {
1027- self . head ( visibility_qualified ( & item. vis , "static" ) ) ;
1028- if * m == ast:: Mutability :: Mut {
1029- self . word_space ( "mut" ) ;
1030- }
1031- self . print_ident ( item. ident ) ;
1032- self . word_space ( ":" ) ;
1033- self . print_type ( t) ;
1034- self . s . word ( ";" ) ;
1035- self . end ( ) ; // end the head-ibox
1036- self . end ( ) ; // end the outer cbox
1026+ ast:: ForeignItemKind :: Static ( ty, mutbl, body) => {
1027+ self . print_item_const ( item. ident , Some ( * mutbl) , ty, body. as_deref ( ) , & item. vis ) ;
10371028 }
10381029 ast:: ForeignItemKind :: TyAlias ( generics, bounds, ty) => {
10391030 self . print_associated_type ( item. ident , generics, bounds, ty. as_deref ( ) ) ;
@@ -1047,24 +1038,31 @@ impl<'a> State<'a> {
10471038 }
10481039 }
10491040
1050- fn print_associated_const (
1041+ fn print_item_const (
10511042 & mut self ,
10521043 ident : ast:: Ident ,
1044+ mutbl : Option < ast:: Mutability > ,
10531045 ty : & ast:: Ty ,
1054- default : Option < & ast:: Expr > ,
1046+ body : Option < & ast:: Expr > ,
10551047 vis : & ast:: Visibility ,
10561048 ) {
1057- self . s . word ( visibility_qualified ( vis, "" ) ) ;
1058- self . word_space ( "const" ) ;
1049+ let leading = match mutbl {
1050+ None => "const " ,
1051+ Some ( ast:: Mutability :: Not ) => "static " ,
1052+ Some ( ast:: Mutability :: Mut ) => "static mut " ,
1053+ } ;
1054+ self . head ( visibility_qualified ( vis, leading) ) ;
10591055 self . print_ident ( ident) ;
10601056 self . word_space ( ":" ) ;
10611057 self . print_type ( ty) ;
1062- if let Some ( expr) = default {
1063- self . s . space ( ) ;
1058+ self . s . space ( ) ;
1059+ self . end ( ) ; // end the head-ibox
1060+ if let Some ( body) = body {
10641061 self . word_space ( "=" ) ;
1065- self . print_expr ( expr ) ;
1062+ self . print_expr ( body ) ;
10661063 }
1067- self . s . word ( ";" )
1064+ self . s . word ( ";" ) ;
1065+ self . end ( ) ; // end the outer cbox
10681066 }
10691067
10701068 fn print_associated_type (
@@ -1114,36 +1112,11 @@ impl<'a> State<'a> {
11141112 self . end ( ) ; // end inner head-block
11151113 self . end ( ) ; // end outer head-block
11161114 }
1117- ast:: ItemKind :: Static ( ref ty, m, ref expr) => {
1118- self . head ( visibility_qualified ( & item. vis , "static" ) ) ;
1119- if m == ast:: Mutability :: Mut {
1120- self . word_space ( "mut" ) ;
1121- }
1122- self . print_ident ( item. ident ) ;
1123- self . word_space ( ":" ) ;
1124- self . print_type ( ty) ;
1125- self . s . space ( ) ;
1126- self . end ( ) ; // end the head-ibox
1127- if let Some ( expr) = expr {
1128- self . word_space ( "=" ) ;
1129- self . print_expr ( expr) ;
1130- }
1131- self . s . word ( ";" ) ;
1132- self . end ( ) ; // end the outer cbox
1115+ ast:: ItemKind :: Static ( ref ty, mutbl, ref body) => {
1116+ self . print_item_const ( item. ident , Some ( mutbl) , ty, body. as_deref ( ) , & item. vis ) ;
11331117 }
1134- ast:: ItemKind :: Const ( ref ty, ref expr) => {
1135- self . head ( visibility_qualified ( & item. vis , "const" ) ) ;
1136- self . print_ident ( item. ident ) ;
1137- self . word_space ( ":" ) ;
1138- self . print_type ( ty) ;
1139- self . s . space ( ) ;
1140- self . end ( ) ; // end the head-ibox
1141- if let Some ( expr) = expr {
1142- self . word_space ( "=" ) ;
1143- self . print_expr ( expr) ;
1144- }
1145- self . s . word ( ";" ) ;
1146- self . end ( ) ; // end the outer cbox
1118+ ast:: ItemKind :: Const ( ref ty, ref body) => {
1119+ self . print_item_const ( item. ident , None , ty, body. as_deref ( ) , & item. vis ) ;
11471120 }
11481121 ast:: ItemKind :: Fn ( ref sig, ref gen, ref body) => {
11491122 self . print_fn_full ( sig, item. ident , gen, & item. vis , body. as_deref ( ) , & item. attrs ) ;
@@ -1469,7 +1442,7 @@ impl<'a> State<'a> {
14691442 self . print_defaultness ( item. defaultness ) ;
14701443 match & item. kind {
14711444 ast:: AssocItemKind :: Const ( ty, expr) => {
1472- self . print_associated_const ( item. ident , ty, expr. as_deref ( ) , & item. vis ) ;
1445+ self . print_item_const ( item. ident , None , ty, expr. as_deref ( ) , & item. vis ) ;
14731446 }
14741447 ast:: AssocItemKind :: Fn ( sig, generics, body) => {
14751448 let body = body. as_deref ( ) ;
0 commit comments