@@ -142,15 +142,16 @@ impl<'a> FmtVisitor<'a> {
142
142
ast:: ForeignItemKind :: Static ( ref ty, is_mutable) => {
143
143
// FIXME(#21): we're dropping potential comments in between the
144
144
// function keywords here.
145
+ let vis = match format_visibility ( & item. vis ) {
146
+ Some ( s) => s,
147
+ None => return ,
148
+ } ;
145
149
let mut_str = if is_mutable {
146
150
"mut "
147
151
} else {
148
152
""
149
153
} ;
150
- let prefix = format ! ( "{}static {}{}: " ,
151
- format_visibility( & item. vis) ,
152
- mut_str,
153
- item. ident) ;
154
+ let prefix = format ! ( "{}static {}{}: " , vis, mut_str, item. ident) ;
154
155
let offset = self . block_indent + prefix. len ( ) ;
155
156
// 1 = ;
156
157
let width = self . config . max_width - offset. width ( ) - 1 ;
@@ -307,7 +308,10 @@ impl<'a> FmtVisitor<'a> {
307
308
enum_def : & ast:: EnumDef ,
308
309
generics : & ast:: Generics ,
309
310
span : Span ) {
310
- let header_str = format_header ( "enum " , ident, vis) ;
311
+ let header_str = match format_header ( "enum " , ident, vis) {
312
+ Some ( s) => s,
313
+ None => return ,
314
+ } ;
311
315
self . buffer . push_str ( & header_str) ;
312
316
313
317
let enum_snippet = self . snippet ( span) ;
@@ -451,7 +455,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
451
455
ref self_ty,
452
456
ref items) = item. node {
453
457
let mut result = String :: new ( ) ;
454
- result. push_str ( format_visibility ( & item. vis ) ) ;
458
+ result. push_str ( try_opt ! ( format_visibility( & item. vis) ) ) ;
455
459
result. push_str ( format_unsafety ( unsafety) ) ;
456
460
result. push_str ( "impl" ) ;
457
461
@@ -619,7 +623,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
619
623
item. node {
620
624
let mut result = String :: new ( ) ;
621
625
let header = format ! ( "{}{}trait {}" ,
622
- format_visibility( & item. vis) ,
626
+ try_opt! ( format_visibility( & item. vis) ) ,
623
627
format_unsafety( unsafety) ,
624
628
item. ident) ;
625
629
@@ -744,7 +748,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
744
748
fn format_unit_struct ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> Option < String > {
745
749
let mut result = String :: with_capacity ( 1024 ) ;
746
750
747
- let header_str = format_header ( item_name, ident, vis) ;
751
+ let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
748
752
result. push_str ( & header_str) ;
749
753
result. push ( ';' ) ;
750
754
@@ -762,7 +766,7 @@ fn format_struct_struct(context: &RewriteContext,
762
766
-> Option < String > {
763
767
let mut result = String :: with_capacity ( 1024 ) ;
764
768
765
- let header_str = format_header ( item_name, ident, vis) ;
769
+ let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
766
770
result. push_str ( & header_str) ;
767
771
768
772
let body_lo = context. codemap . span_after ( span, "{" ) ;
@@ -843,7 +847,7 @@ fn format_tuple_struct(context: &RewriteContext,
843
847
-> Option < String > {
844
848
let mut result = String :: with_capacity ( 1024 ) ;
845
849
846
- let header_str = format_header ( item_name, ident, vis) ;
850
+ let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
847
851
result. push_str ( & header_str) ;
848
852
849
853
// FIXME(#919): don't lose comments on empty tuple structs.
@@ -929,7 +933,7 @@ pub fn rewrite_type_alias(context: &RewriteContext,
929
933
-> Option < String > {
930
934
let mut result = String :: new ( ) ;
931
935
932
- result. push_str ( & format_visibility ( & vis) ) ;
936
+ result. push_str ( & try_opt ! ( format_visibility( & vis) ) ) ;
933
937
result. push_str ( "type " ) ;
934
938
result. push_str ( & ident. to_string ( ) ) ;
935
939
@@ -997,7 +1001,7 @@ impl Rewrite for ast::StructField {
997
1001
}
998
1002
999
1003
let name = self . ident ;
1000
- let vis = format_visibility ( & self . vis ) ;
1004
+ let vis = try_opt ! ( format_visibility( & self . vis) ) ;
1001
1005
let mut attr_str = try_opt ! ( self . attrs
1002
1006
. rewrite( context, context. config. max_width - offset. width( ) , offset) ) ;
1003
1007
if !attr_str. is_empty ( ) {
@@ -1026,7 +1030,7 @@ pub fn rewrite_static(prefix: &str,
1026
1030
context : & RewriteContext )
1027
1031
-> Option < String > {
1028
1032
let prefix = format ! ( "{}{} {}{}: " ,
1029
- format_visibility( vis) ,
1033
+ try_opt! ( format_visibility( vis) ) ,
1030
1034
prefix,
1031
1035
format_mutability( mutability) ,
1032
1036
ident) ;
@@ -1245,7 +1249,7 @@ fn rewrite_fn_base(context: &RewriteContext,
1245
1249
1246
1250
let mut result = String :: with_capacity ( 1024 ) ;
1247
1251
// Vis unsafety abi.
1248
- result. push_str ( format_visibility ( vis) ) ;
1252
+ result. push_str ( try_opt ! ( format_visibility( vis) ) ) ;
1249
1253
1250
1254
if let ast:: Constness :: Const = constness {
1251
1255
result. push_str ( "const " ) ;
@@ -1801,8 +1805,8 @@ fn rewrite_where_clause(context: &RewriteContext,
1801
1805
}
1802
1806
}
1803
1807
1804
- fn format_header ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> String {
1805
- format ! ( "{}{}{}" , format_visibility( vis) , item_name, ident)
1808
+ fn format_header ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> Option < String > {
1809
+ Some ( format ! ( "{}{}{}" , try_opt! ( format_visibility( vis) ) , item_name, ident) )
1806
1810
}
1807
1811
1808
1812
fn format_generics ( context : & RewriteContext ,
0 commit comments