@@ -96,13 +96,9 @@ impl Rewrite for ast::Local {
9696 let mut infix = String :: with_capacity ( 32 ) ;
9797
9898 if let Some ( ref ty) = self . ty {
99-
100- let force_space_after_colon = match ty. clone ( ) . into_inner ( ) . kind {
101- ast:: TyKind :: Path ( None , _) => true ,
102- _ => false ,
103- } ;
104-
99+ let force_space_after_colon = is_ty_kind_with_global_decl ( & ty. clone ( ) . into_inner ( ) . kind ) ;
105100 let separator = type_annotation_separator ( context. config , force_space_after_colon) ;
101+
106102 let ty_shape = if pat_str. contains ( '\n' ) {
107103 shape. with_max_width ( context. config )
108104 } else {
@@ -1945,10 +1941,7 @@ pub(crate) fn rewrite_struct_field(
19451941 return Ok ( context. snippet ( field. span ( ) ) . to_owned ( ) ) ;
19461942 }
19471943
1948- let force_space_after_colon = match field. ty . clone ( ) . into_inner ( ) . kind {
1949- ast:: TyKind :: Path ( None , _) => true ,
1950- _ => false ,
1951- } ;
1944+ let force_space_after_colon = is_ty_kind_with_global_decl ( & field. ty . clone ( ) . into_inner ( ) . kind ) ;
19521945 let type_annotation_spacing = type_annotation_spacing ( context. config , force_space_after_colon) ;
19531946 let prefix = rewrite_struct_field_prefix ( context, field) ?;
19541947
@@ -2088,6 +2081,19 @@ impl<'a> StaticParts<'a> {
20882081 }
20892082}
20902083
2084+ fn is_ty_kind_with_global_decl ( ty_kind : & ast:: TyKind ) -> bool {
2085+ match ty_kind {
2086+ ast:: TyKind :: Path ( None , ast_path) => {
2087+ let segments = & ast_path. segments ;
2088+ match segments. first ( ) {
2089+ Some ( path_segment) => path_segment. ident . name == symbol:: kw:: PathRoot ,
2090+ None => false ,
2091+ }
2092+ } ,
2093+ _ => false ,
2094+ }
2095+ }
2096+
20912097fn rewrite_static (
20922098 context : & RewriteContext < ' _ > ,
20932099 static_parts : & StaticParts < ' _ > ,
@@ -2103,10 +2109,7 @@ fn rewrite_static(
21032109
21042110 // if after a semicolon is absolute path declaration (::) need to force
21052111 // space after colon, because ::: syntax cannot compile
2106- let force_space_after_colon = match static_parts. ty . kind {
2107- ast:: TyKind :: Path ( None , _) => true ,
2108- _ => false ,
2109- } ;
2112+ let force_space_after_colon = is_ty_kind_with_global_decl ( & static_parts. ty . kind ) ;
21102113 let colon = colon_spaces ( context. config , force_space_after_colon) ;
21112114
21122115 let mut prefix = format ! (
0 commit comments