@@ -139,10 +139,7 @@ impl<'a> FmtVisitor<'a> {
139
139
ast:: ForeignItemKind :: Static ( ref ty, is_mutable) => {
140
140
// FIXME(#21): we're dropping potential comments in between the
141
141
// function keywords here.
142
- let vis = match format_visibility ( & item. vis ) {
143
- Some ( s) => s,
144
- None => return ,
145
- } ;
142
+ let vis = format_visibility ( & item. vis ) ;
146
143
let mut_str = if is_mutable {
147
144
"mut "
148
145
} else {
@@ -305,11 +302,7 @@ impl<'a> FmtVisitor<'a> {
305
302
enum_def : & ast:: EnumDef ,
306
303
generics : & ast:: Generics ,
307
304
span : Span ) {
308
- let header_str = match format_header ( "enum " , ident, vis) {
309
- Some ( s) => s,
310
- None => return ,
311
- } ;
312
- self . buffer . push_str ( & header_str) ;
305
+ self . buffer . push_str ( & format_header ( "enum " , ident, vis) ) ;
313
306
314
307
let enum_snippet = self . snippet ( span) ;
315
308
let body_start = span. lo + BytePos ( enum_snippet. find_uncommented ( "{" ) . unwrap ( ) as u32 + 1 ) ;
@@ -453,7 +446,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
453
446
ref self_ty,
454
447
ref items) = item. node {
455
448
let mut result = String :: new ( ) ;
456
- result. push_str ( try_opt ! ( format_visibility( & item. vis) ) ) ;
449
+ result. push_str ( & * format_visibility ( & item. vis ) ) ;
457
450
result. push_str ( format_unsafety ( unsafety) ) ;
458
451
result. push_str ( "impl" ) ;
459
452
@@ -593,7 +586,7 @@ pub fn format_struct(context: &RewriteContext,
593
586
one_line_width : Option < usize > )
594
587
-> Option < String > {
595
588
match * struct_def {
596
- ast:: VariantData :: Unit ( ..) => format_unit_struct ( item_name, ident, vis) ,
589
+ ast:: VariantData :: Unit ( ..) => Some ( format_unit_struct ( item_name, ident, vis) ) ,
597
590
ast:: VariantData :: Tuple ( ref fields, _) => {
598
591
format_tuple_struct ( context,
599
592
item_name,
@@ -623,7 +616,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
623
616
item. node {
624
617
let mut result = String :: new ( ) ;
625
618
let header = format ! ( "{}{}trait {}" ,
626
- try_opt! ( format_visibility( & item. vis) ) ,
619
+ format_visibility( & item. vis) ,
627
620
format_unsafety( unsafety) ,
628
621
item. ident) ;
629
622
@@ -744,14 +737,8 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
744
737
}
745
738
}
746
739
747
- fn format_unit_struct ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> Option < String > {
748
- let mut result = String :: with_capacity ( 1024 ) ;
749
-
750
- let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
751
- result. push_str ( & header_str) ;
752
- result. push ( ';' ) ;
753
-
754
- Some ( result)
740
+ fn format_unit_struct ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> String {
741
+ format ! ( "{};" , format_header( item_name, ident, vis) )
755
742
}
756
743
757
744
fn format_struct_struct ( context : & RewriteContext ,
@@ -766,7 +753,7 @@ fn format_struct_struct(context: &RewriteContext,
766
753
-> Option < String > {
767
754
let mut result = String :: with_capacity ( 1024 ) ;
768
755
769
- let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
756
+ let header_str = format_header ( item_name, ident, vis) ;
770
757
result. push_str ( & header_str) ;
771
758
772
759
let body_lo = context. codemap . span_after ( span, "{" ) ;
@@ -859,7 +846,7 @@ fn format_tuple_struct(context: &RewriteContext,
859
846
-> Option < String > {
860
847
let mut result = String :: with_capacity ( 1024 ) ;
861
848
862
- let header_str = try_opt ! ( format_header( item_name, ident, vis) ) ;
849
+ let header_str = format_header ( item_name, ident, vis) ;
863
850
result. push_str ( & header_str) ;
864
851
865
852
// FIXME(#919): don't lose comments on empty tuple structs.
@@ -945,7 +932,7 @@ pub fn rewrite_type_alias(context: &RewriteContext,
945
932
-> Option < String > {
946
933
let mut result = String :: new ( ) ;
947
934
948
- result. push_str ( & try_opt ! ( format_visibility( & vis) ) ) ;
935
+ result. push_str ( & format_visibility ( & vis) ) ;
949
936
result. push_str ( "type " ) ;
950
937
result. push_str ( & ident. to_string ( ) ) ;
951
938
@@ -1013,7 +1000,7 @@ impl Rewrite for ast::StructField {
1013
1000
}
1014
1001
1015
1002
let name = self . ident ;
1016
- let vis = try_opt ! ( format_visibility( & self . vis) ) ;
1003
+ let vis = format_visibility ( & self . vis ) ;
1017
1004
let mut attr_str = try_opt ! ( self . attrs
1018
1005
. rewrite( context, context. config. max_width - offset. width( ) , offset) ) ;
1019
1006
if !attr_str. is_empty ( ) {
@@ -1042,7 +1029,7 @@ pub fn rewrite_static(prefix: &str,
1042
1029
context : & RewriteContext )
1043
1030
-> Option < String > {
1044
1031
let prefix = format ! ( "{}{} {}{}: " ,
1045
- try_opt! ( format_visibility( vis) ) ,
1032
+ format_visibility( vis) ,
1046
1033
prefix,
1047
1034
format_mutability( mutability) ,
1048
1035
ident) ;
@@ -1260,7 +1247,7 @@ fn rewrite_fn_base(context: &RewriteContext,
1260
1247
1261
1248
let mut result = String :: with_capacity ( 1024 ) ;
1262
1249
// Vis unsafety abi.
1263
- result. push_str ( try_opt ! ( format_visibility( vis) ) ) ;
1250
+ result. push_str ( & * format_visibility ( vis) ) ;
1264
1251
1265
1252
if let ast:: Constness :: Const = constness {
1266
1253
result. push_str ( "const " ) ;
@@ -1816,8 +1803,8 @@ fn rewrite_where_clause(context: &RewriteContext,
1816
1803
}
1817
1804
}
1818
1805
1819
- fn format_header ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> Option < String > {
1820
- Some ( format ! ( "{}{}{}" , try_opt! ( format_visibility( vis) ) , item_name, ident) )
1806
+ fn format_header ( item_name : & str , ident : ast:: Ident , vis : & ast:: Visibility ) -> String {
1807
+ format ! ( "{}{}{}" , format_visibility( vis) , item_name, ident)
1821
1808
}
1822
1809
1823
1810
fn format_generics ( context : & RewriteContext ,
0 commit comments