@@ -25,6 +25,7 @@ use hir;
25
25
use hir:: { PatKind , GenericBound , TraitBoundModifier , RangeEnd } ;
26
26
use hir:: { GenericParam , GenericParamKind , GenericArg } ;
27
27
28
+ use std:: borrow:: Cow ;
28
29
use std:: cell:: Cell ;
29
30
use std:: io:: { self , Write , Read } ;
30
31
use std:: iter:: Peekable ;
@@ -209,7 +210,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
209
210
String :: from_utf8 ( wr) . unwrap ( )
210
211
}
211
212
212
- pub fn visibility_qualified ( vis : & hir:: Visibility , w : & str ) -> String {
213
+ pub fn visibility_qualified < S : Into < Cow < ' static , str > > > ( vis : & hir:: Visibility , w : S ) -> String {
213
214
to_string ( NO_ANN , |s| {
214
215
s. print_visibility ( vis) ?;
215
216
s. s . word ( w)
@@ -226,12 +227,13 @@ impl<'a> State<'a> {
226
227
self . s . word ( " " )
227
228
}
228
229
229
- pub fn word_nbsp ( & mut self , w : & str ) -> io:: Result < ( ) > {
230
+ pub fn word_nbsp < S : Into < Cow < ' static , str > > > ( & mut self , w : S ) -> io:: Result < ( ) > {
230
231
self . s . word ( w) ?;
231
232
self . nbsp ( )
232
233
}
233
234
234
- pub fn head ( & mut self , w : & str ) -> io:: Result < ( ) > {
235
+ pub fn head < S : Into < Cow < ' static , str > > > ( & mut self , w : S ) -> io:: Result < ( ) > {
236
+ let w = w. into ( ) ;
235
237
// outer-box is consistent
236
238
self . cbox ( indent_unit) ?;
237
239
// head-box is inconsistent
@@ -303,7 +305,7 @@ impl<'a> State<'a> {
303
305
pub fn synth_comment ( & mut self , text : String ) -> io:: Result < ( ) > {
304
306
self . s . word ( "/*" ) ?;
305
307
self . s . space ( ) ?;
306
- self . s . word ( & text[ .. ] ) ?;
308
+ self . s . word ( text) ?;
307
309
self . s . space ( ) ?;
308
310
self . s . word ( "*/" )
309
311
}
@@ -468,7 +470,7 @@ impl<'a> State<'a> {
468
470
self . end ( ) // end the outer fn box
469
471
}
470
472
hir:: ForeignItemKind :: Static ( ref t, m) => {
471
- self . head ( & visibility_qualified ( & item. vis , "static" ) ) ?;
473
+ self . head ( visibility_qualified ( & item. vis , "static" ) ) ?;
472
474
if m {
473
475
self . word_space ( "mut" ) ?;
474
476
}
@@ -480,7 +482,7 @@ impl<'a> State<'a> {
480
482
self . end ( ) // end the outer cbox
481
483
}
482
484
hir:: ForeignItemKind :: Type => {
483
- self . head ( & visibility_qualified ( & item. vis , "type" ) ) ?;
485
+ self . head ( visibility_qualified ( & item. vis , "type" ) ) ?;
484
486
self . print_name ( item. name ) ?;
485
487
self . s . word ( ";" ) ?;
486
488
self . end ( ) ?; // end the head-ibox
@@ -495,7 +497,7 @@ impl<'a> State<'a> {
495
497
default : Option < hir:: BodyId > ,
496
498
vis : & hir:: Visibility )
497
499
-> io:: Result < ( ) > {
498
- self . s . word ( & visibility_qualified ( vis, "" ) ) ?;
500
+ self . s . word ( visibility_qualified ( vis, "" ) ) ?;
499
501
self . word_space ( "const" ) ?;
500
502
self . print_ident ( ident) ?;
501
503
self . word_space ( ":" ) ?;
@@ -534,7 +536,7 @@ impl<'a> State<'a> {
534
536
self . ann . pre ( self , AnnNode :: Item ( item) ) ?;
535
537
match item. node {
536
538
hir:: ItemKind :: ExternCrate ( orig_name) => {
537
- self . head ( & visibility_qualified ( & item. vis , "extern crate" ) ) ?;
539
+ self . head ( visibility_qualified ( & item. vis , "extern crate" ) ) ?;
538
540
if let Some ( orig_name) = orig_name {
539
541
self . print_name ( orig_name) ?;
540
542
self . s . space ( ) ?;
@@ -547,7 +549,7 @@ impl<'a> State<'a> {
547
549
self . end ( ) ?; // end outer head-block
548
550
}
549
551
hir:: ItemKind :: Use ( ref path, kind) => {
550
- self . head ( & visibility_qualified ( & item. vis , "use" ) ) ?;
552
+ self . head ( visibility_qualified ( & item. vis , "use" ) ) ?;
551
553
self . print_path ( path, false ) ?;
552
554
553
555
match kind {
@@ -566,7 +568,7 @@ impl<'a> State<'a> {
566
568
self . end ( ) ?; // end outer head-block
567
569
}
568
570
hir:: ItemKind :: Static ( ref ty, m, expr) => {
569
- self . head ( & visibility_qualified ( & item. vis , "static" ) ) ?;
571
+ self . head ( visibility_qualified ( & item. vis , "static" ) ) ?;
570
572
if m == hir:: MutMutable {
571
573
self . word_space ( "mut" ) ?;
572
574
}
@@ -582,7 +584,7 @@ impl<'a> State<'a> {
582
584
self . end ( ) ?; // end the outer cbox
583
585
}
584
586
hir:: ItemKind :: Const ( ref ty, expr) => {
585
- self . head ( & visibility_qualified ( & item. vis , "const" ) ) ?;
587
+ self . head ( visibility_qualified ( & item. vis , "const" ) ) ?;
586
588
self . print_name ( item. name ) ?;
587
589
self . word_space ( ":" ) ?;
588
590
self . print_type ( & ty) ?;
@@ -609,7 +611,7 @@ impl<'a> State<'a> {
609
611
self . ann . nested ( self , Nested :: Body ( body) ) ?;
610
612
}
611
613
hir:: ItemKind :: Mod ( ref _mod) => {
612
- self . head ( & visibility_qualified ( & item. vis , "mod" ) ) ?;
614
+ self . head ( visibility_qualified ( & item. vis , "mod" ) ) ?;
613
615
self . print_name ( item. name ) ?;
614
616
self . nbsp ( ) ?;
615
617
self . bopen ( ) ?;
@@ -618,18 +620,18 @@ impl<'a> State<'a> {
618
620
}
619
621
hir:: ItemKind :: ForeignMod ( ref nmod) => {
620
622
self . head ( "extern" ) ?;
621
- self . word_nbsp ( & nmod. abi . to_string ( ) ) ?;
623
+ self . word_nbsp ( nmod. abi . to_string ( ) ) ?;
622
624
self . bopen ( ) ?;
623
625
self . print_foreign_mod ( nmod, & item. attrs ) ?;
624
626
self . bclose ( item. span ) ?;
625
627
}
626
628
hir:: ItemKind :: GlobalAsm ( ref ga) => {
627
- self . head ( & visibility_qualified ( & item. vis , "global asm" ) ) ?;
628
- self . s . word ( & ga. asm . as_str ( ) ) ?;
629
+ self . head ( visibility_qualified ( & item. vis , "global asm" ) ) ?;
630
+ self . s . word ( ga. asm . as_str ( ) . get ( ) ) ?;
629
631
self . end ( ) ?
630
632
}
631
633
hir:: ItemKind :: Ty ( ref ty, ref generics) => {
632
- self . head ( & visibility_qualified ( & item. vis , "type" ) ) ?;
634
+ self . head ( visibility_qualified ( & item. vis , "type" ) ) ?;
633
635
self . print_name ( item. name ) ?;
634
636
self . print_generic_params ( & generics. params ) ?;
635
637
self . end ( ) ?; // end the inner ibox
@@ -642,7 +644,7 @@ impl<'a> State<'a> {
642
644
self . end ( ) ?; // end the outer ibox
643
645
}
644
646
hir:: ItemKind :: Existential ( ref exist) => {
645
- self . head ( & visibility_qualified ( & item. vis , "existential type" ) ) ?;
647
+ self . head ( visibility_qualified ( & item. vis , "existential type" ) ) ?;
646
648
self . print_name ( item. name ) ?;
647
649
self . print_generic_params ( & exist. generics . params ) ?;
648
650
self . end ( ) ?; // end the inner ibox
@@ -668,11 +670,11 @@ impl<'a> State<'a> {
668
670
self . print_enum_def ( enum_definition, params, item. name , item. span , & item. vis ) ?;
669
671
}
670
672
hir:: ItemKind :: Struct ( ref struct_def, ref generics) => {
671
- self . head ( & visibility_qualified ( & item. vis , "struct" ) ) ?;
673
+ self . head ( visibility_qualified ( & item. vis , "struct" ) ) ?;
672
674
self . print_struct ( struct_def, generics, item. name , item. span , true ) ?;
673
675
}
674
676
hir:: ItemKind :: Union ( ref struct_def, ref generics) => {
675
- self . head ( & visibility_qualified ( & item. vis , "union" ) ) ?;
677
+ self . head ( visibility_qualified ( & item. vis , "union" ) ) ?;
676
678
self . print_struct ( struct_def, generics, item. name , item. span , true ) ?;
677
679
}
678
680
hir:: ItemKind :: Impl ( unsafety,
@@ -795,7 +797,7 @@ impl<'a> State<'a> {
795
797
span : syntax_pos:: Span ,
796
798
visibility : & hir:: Visibility )
797
799
-> io:: Result < ( ) > {
798
- self . head ( & visibility_qualified ( visibility, "enum" ) ) ?;
800
+ self . head ( visibility_qualified ( visibility, "enum" ) ) ?;
799
801
self . print_name ( name) ?;
800
802
self . print_generic_params ( & generics. params ) ?;
801
803
self . print_where_clause ( & generics. where_clause ) ?;
@@ -1587,14 +1589,14 @@ impl<'a> State<'a> {
1587
1589
}
1588
1590
1589
1591
pub fn print_usize ( & mut self , i : usize ) -> io:: Result < ( ) > {
1590
- self . s . word ( & i. to_string ( ) )
1592
+ self . s . word ( i. to_string ( ) )
1591
1593
}
1592
1594
1593
1595
pub fn print_ident ( & mut self , ident : ast:: Ident ) -> io:: Result < ( ) > {
1594
1596
if ident. is_raw_guess ( ) {
1595
- self . s . word ( & format ! ( "r#{}" , ident. name) ) ?;
1597
+ self . s . word ( format ! ( "r#{}" , ident. name) ) ?;
1596
1598
} else {
1597
- self . s . word ( & ident. as_str ( ) ) ?;
1599
+ self . s . word ( ident. as_str ( ) . get ( ) ) ?;
1598
1600
}
1599
1601
self . ann . post ( self , AnnNode :: Name ( & ident. name ) )
1600
1602
}
@@ -2010,7 +2012,7 @@ impl<'a> State<'a> {
2010
2012
self . commasep ( Inconsistent , & decl. inputs , |s, ty| {
2011
2013
s. ibox ( indent_unit) ?;
2012
2014
if let Some ( arg_name) = arg_names. get ( i) {
2013
- s. s . word ( & arg_name. as_str ( ) ) ?;
2015
+ s. s . word ( arg_name. as_str ( ) . get ( ) ) ?;
2014
2016
s. s . word ( ":" ) ?;
2015
2017
s. s . space ( ) ?;
2016
2018
} else if let Some ( body_id) = body_id {
@@ -2073,7 +2075,8 @@ impl<'a> State<'a> {
2073
2075
}
2074
2076
}
2075
2077
2076
- pub fn print_bounds ( & mut self , prefix : & str , bounds : & [ hir:: GenericBound ] ) -> io:: Result < ( ) > {
2078
+ pub fn print_bounds ( & mut self , prefix : & ' static str , bounds : & [ hir:: GenericBound ] )
2079
+ -> io:: Result < ( ) > {
2077
2080
if !bounds. is_empty ( ) {
2078
2081
self . s . word ( prefix) ?;
2079
2082
let mut first = true ;
@@ -2322,7 +2325,7 @@ impl<'a> State<'a> {
2322
2325
Some ( Abi :: Rust ) => Ok ( ( ) ) ,
2323
2326
Some ( abi) => {
2324
2327
self . word_nbsp ( "extern" ) ?;
2325
- self . word_nbsp ( & abi. to_string ( ) )
2328
+ self . word_nbsp ( abi. to_string ( ) )
2326
2329
}
2327
2330
None => Ok ( ( ) ) ,
2328
2331
}
@@ -2332,7 +2335,7 @@ impl<'a> State<'a> {
2332
2335
match opt_abi {
2333
2336
Some ( abi) => {
2334
2337
self . word_nbsp ( "extern" ) ?;
2335
- self . word_nbsp ( & abi. to_string ( ) )
2338
+ self . word_nbsp ( abi. to_string ( ) )
2336
2339
}
2337
2340
None => Ok ( ( ) ) ,
2338
2341
}
@@ -2342,7 +2345,7 @@ impl<'a> State<'a> {
2342
2345
header : hir:: FnHeader ,
2343
2346
vis : & hir:: Visibility )
2344
2347
-> io:: Result < ( ) > {
2345
- self . s . word ( & visibility_qualified ( vis, "" ) ) ?;
2348
+ self . s . word ( visibility_qualified ( vis, "" ) ) ?;
2346
2349
2347
2350
match header. constness {
2348
2351
hir:: Constness :: NotConst => { }
@@ -2358,7 +2361,7 @@ impl<'a> State<'a> {
2358
2361
2359
2362
if header. abi != Abi :: Rust {
2360
2363
self . word_nbsp ( "extern" ) ?;
2361
- self . word_nbsp ( & header. abi . to_string ( ) ) ?;
2364
+ self . word_nbsp ( header. abi . to_string ( ) ) ?;
2362
2365
}
2363
2366
2364
2367
self . s . word ( "fn" )
0 commit comments