@@ -2005,7 +2005,7 @@ pub(crate) struct StaticParts<'a> {
20052005 vis : & ' a ast:: Visibility ,
20062006 ident : symbol:: Ident ,
20072007 generics : Option < & ' a ast:: Generics > ,
2008- ty : & ' a ast:: Ty ,
2008+ ty : Option < & ' a ast:: Ty > ,
20092009 mutability : ast:: Mutability ,
20102010 expr_opt : Option < & ' a ast:: Expr > ,
20112011 defaultness : Option < ast:: Defaultness > ,
@@ -2021,7 +2021,7 @@ impl<'a> StaticParts<'a> {
20212021 "static" ,
20222022 s. safety ,
20232023 s. ident ,
2024- & s. ty ,
2024+ Some ( & * s. ty ) ,
20252025 s. mutability ,
20262026 s. expr . as_deref ( ) ,
20272027 None ,
@@ -2031,7 +2031,7 @@ impl<'a> StaticParts<'a> {
20312031 "const" ,
20322032 ast:: Safety :: Default ,
20332033 c. ident ,
2034- & c. ty ,
2034+ c. ty . as_non_default ( ) ,
20352035 ast:: Mutability :: Not ,
20362036 c. rhs . as_ref ( ) . map ( |rhs| rhs. expr ( ) ) ,
20372037 Some ( & c. generics ) ,
@@ -2056,7 +2056,7 @@ impl<'a> StaticParts<'a> {
20562056 let ( defaultness, ty, expr_opt, generics) = match & ti. kind {
20572057 ast:: AssocItemKind :: Const ( c) => (
20582058 c. defaultness ,
2059- & c. ty ,
2059+ c. ty . as_non_default ( ) ,
20602060 c. rhs . as_ref ( ) . map ( |rhs| rhs. expr ( ) ) ,
20612061 Some ( & c. generics ) ,
20622062 ) ,
@@ -2080,7 +2080,7 @@ impl<'a> StaticParts<'a> {
20802080 let ( defaultness, ty, expr_opt, generics) = match & ii. kind {
20812081 ast:: AssocItemKind :: Const ( c) => (
20822082 c. defaultness ,
2083- & c. ty ,
2083+ c. ty . as_non_default ( ) ,
20842084 c. rhs . as_ref ( ) . map ( |rhs| rhs. expr ( ) ) ,
20852085 Some ( & c. generics ) ,
20862086 ) ,
@@ -2114,35 +2114,38 @@ fn rewrite_static(
21142114 return None ;
21152115 }
21162116
2117- let colon = colon_spaces ( context. config ) ;
21182117 let mut prefix = format ! (
2119- "{}{}{}{} {}{}{} " ,
2118+ "{}{}{}{} {}{}" ,
21202119 format_visibility( context, static_parts. vis) ,
21212120 static_parts. defaultness. map_or( "" , format_defaultness) ,
21222121 format_safety( static_parts. safety) ,
21232122 static_parts. prefix,
21242123 format_mutability( static_parts. mutability) ,
21252124 rewrite_ident( context, static_parts. ident) ,
2126- colon,
21272125 ) ;
2128- // 2 = " =".len()
2129- let ty_shape =
2130- Shape :: indented ( offset. block_only ( ) , context. config ) . offset_left ( prefix. len ( ) + 2 ) ?;
2131- let ty_str = match static_parts. ty . rewrite ( context, ty_shape) {
2132- Some ( ty_str) => ty_str,
2133- None => {
2134- if prefix. ends_with ( ' ' ) {
2135- prefix. pop ( ) ;
2126+ let ty_str = match static_parts. ty {
2127+ Some ( ty) => {
2128+ prefix. push_str ( colon_spaces ( context. config ) ) ;
2129+ let ty_shape = Shape :: indented ( offset. block_only ( ) , context. config )
2130+ . offset_left ( prefix. len ( ) + const { " =" . len ( ) } ) ?;
2131+ match ty. rewrite ( context, ty_shape) {
2132+ Some ( ty_str) => ty_str,
2133+ None => {
2134+ if prefix. ends_with ( ' ' ) {
2135+ prefix. pop ( ) ;
2136+ }
2137+ let nested_indent = offset. block_indent ( context. config ) ;
2138+ let nested_shape = Shape :: indented ( nested_indent, context. config ) ;
2139+ let ty_str = ty. rewrite ( context, nested_shape) ?;
2140+ format ! (
2141+ "{}{}" ,
2142+ nested_indent. to_string_with_newline( context. config) ,
2143+ ty_str
2144+ )
2145+ }
21362146 }
2137- let nested_indent = offset. block_indent ( context. config ) ;
2138- let nested_shape = Shape :: indented ( nested_indent, context. config ) ;
2139- let ty_str = static_parts. ty . rewrite ( context, nested_shape) ?;
2140- format ! (
2141- "{}{}" ,
2142- nested_indent. to_string_with_newline( context. config) ,
2143- ty_str
2144- )
21452147 }
2148+ None => "" . to_string ( ) ,
21462149 } ;
21472150
21482151 if let Some ( expr) = static_parts. expr_opt {
0 commit comments