@@ -8,12 +8,11 @@ use rustc_ast_pretty::pprust::{Comments, PrintState};
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: { GenericArg , GenericParam , GenericParamKind , Node , Term } ;
10
10
use rustc_hir:: { GenericBound , PatKind , RangeEnd , TraitBoundModifier } ;
11
- use rustc_span:: source_map:: { SourceMap , Spanned } ;
11
+ use rustc_span:: source_map:: SourceMap ;
12
12
use rustc_span:: symbol:: { kw, Ident , IdentPrinter , Symbol } ;
13
13
use rustc_span:: { self , FileName } ;
14
14
use rustc_target:: spec:: abi:: Abi ;
15
15
16
- use std:: borrow:: Cow ;
17
16
use std:: cell:: Cell ;
18
17
use std:: vec;
19
18
@@ -190,13 +189,6 @@ where
190
189
printer. s . eof ( )
191
190
}
192
191
193
- pub fn visibility_qualified < S : Into < Cow < ' static , str > > > ( vis : & hir:: Visibility < ' _ > , w : S ) -> String {
194
- to_string ( NO_ANN , |s| {
195
- s. print_visibility ( vis) ;
196
- s. word ( w)
197
- } )
198
- }
199
-
200
192
pub fn generic_params_to_string ( generic_params : & [ GenericParam < ' _ > ] ) -> String {
201
193
to_string ( NO_ANN , |s| s. print_generic_params ( generic_params) )
202
194
}
@@ -222,21 +214,19 @@ pub fn fn_to_string(
222
214
header : hir:: FnHeader ,
223
215
name : Option < Symbol > ,
224
216
generics : & hir:: Generics < ' _ > ,
225
- vis : & hir:: Visibility < ' _ > ,
226
217
arg_names : & [ Ident ] ,
227
218
body_id : Option < hir:: BodyId > ,
228
219
) -> String {
229
- to_string ( NO_ANN , |s| s. print_fn ( decl, header, name, generics, vis , arg_names, body_id) )
220
+ to_string ( NO_ANN , |s| s. print_fn ( decl, header, name, generics, arg_names, body_id) )
230
221
}
231
222
232
223
pub fn enum_def_to_string (
233
224
enum_definition : & hir:: EnumDef < ' _ > ,
234
225
generics : & hir:: Generics < ' _ > ,
235
226
name : Symbol ,
236
227
span : rustc_span:: Span ,
237
- visibility : & hir:: Visibility < ' _ > ,
238
228
) -> String {
239
- to_string ( NO_ANN , |s| s. print_enum_def ( enum_definition, generics, name, span, visibility ) )
229
+ to_string ( NO_ANN , |s| s. print_enum_def ( enum_definition, generics, name, span) )
240
230
}
241
231
242
232
impl < ' a > State < ' a > {
@@ -394,7 +384,6 @@ impl<'a> State<'a> {
394
384
} ,
395
385
Some ( item. ident . name ) ,
396
386
generics,
397
- & item. vis ,
398
387
arg_names,
399
388
None ,
400
389
) ;
@@ -403,7 +392,7 @@ impl<'a> State<'a> {
403
392
self . end ( ) // end the outer fn box
404
393
}
405
394
hir:: ForeignItemKind :: Static ( ref t, m) => {
406
- self . head ( visibility_qualified ( & item . vis , "static" ) ) ;
395
+ self . head ( "static" ) ;
407
396
if m == hir:: Mutability :: Mut {
408
397
self . word_space ( "mut" ) ;
409
398
}
@@ -415,7 +404,7 @@ impl<'a> State<'a> {
415
404
self . end ( ) // end the outer cbox
416
405
}
417
406
hir:: ForeignItemKind :: Type => {
418
- self . head ( visibility_qualified ( & item . vis , "type" ) ) ;
407
+ self . head ( "type" ) ;
419
408
self . print_ident ( item. ident ) ;
420
409
self . word ( ";" ) ;
421
410
self . end ( ) ; // end the head-ibox
@@ -429,9 +418,8 @@ impl<'a> State<'a> {
429
418
ident : Ident ,
430
419
ty : & hir:: Ty < ' _ > ,
431
420
default : Option < hir:: BodyId > ,
432
- vis : & hir:: Visibility < ' _ > ,
433
421
) {
434
- self . word ( visibility_qualified ( vis , "" ) ) ;
422
+ self . head ( "" ) ;
435
423
self . word_space ( "const" ) ;
436
424
self . print_ident ( ident) ;
437
425
self . word_space ( ":" ) ;
@@ -472,7 +460,7 @@ impl<'a> State<'a> {
472
460
generics : & hir:: Generics < ' _ > ,
473
461
inner : impl Fn ( & mut Self ) ,
474
462
) {
475
- self . head ( visibility_qualified ( & item . vis , "type" ) ) ;
463
+ self . head ( "type" ) ;
476
464
self . print_ident ( item. ident ) ;
477
465
self . print_generic_params ( & generics. params ) ;
478
466
self . end ( ) ; // end the inner ibox
@@ -493,7 +481,7 @@ impl<'a> State<'a> {
493
481
self . ann . pre ( self , AnnNode :: Item ( item) ) ;
494
482
match item. kind {
495
483
hir:: ItemKind :: ExternCrate ( orig_name) => {
496
- self . head ( visibility_qualified ( & item . vis , "extern crate" ) ) ;
484
+ self . head ( "extern crate" ) ;
497
485
if let Some ( orig_name) = orig_name {
498
486
self . print_name ( orig_name) ;
499
487
self . space ( ) ;
@@ -506,7 +494,7 @@ impl<'a> State<'a> {
506
494
self . end ( ) ; // end outer head-block
507
495
}
508
496
hir:: ItemKind :: Use ( ref path, kind) => {
509
- self . head ( visibility_qualified ( & item . vis , "use" ) ) ;
497
+ self . head ( "use" ) ;
510
498
self . print_path ( path, false ) ;
511
499
512
500
match kind {
@@ -525,7 +513,7 @@ impl<'a> State<'a> {
525
513
self . end ( ) ; // end outer head-block
526
514
}
527
515
hir:: ItemKind :: Static ( ref ty, m, expr) => {
528
- self . head ( visibility_qualified ( & item . vis , "static" ) ) ;
516
+ self . head ( "static" ) ;
529
517
if m == hir:: Mutability :: Mut {
530
518
self . word_space ( "mut" ) ;
531
519
}
@@ -541,7 +529,7 @@ impl<'a> State<'a> {
541
529
self . end ( ) ; // end the outer cbox
542
530
}
543
531
hir:: ItemKind :: Const ( ref ty, expr) => {
544
- self . head ( visibility_qualified ( & item . vis , "const" ) ) ;
532
+ self . head ( "const" ) ;
545
533
self . print_ident ( item. ident ) ;
546
534
self . word_space ( ":" ) ;
547
535
self . print_type ( & ty) ;
@@ -560,7 +548,6 @@ impl<'a> State<'a> {
560
548
sig. header ,
561
549
Some ( item. ident . name ) ,
562
550
param_names,
563
- & item. vis ,
564
551
& [ ] ,
565
552
Some ( body) ,
566
553
) ;
@@ -570,12 +557,10 @@ impl<'a> State<'a> {
570
557
self . ann . nested ( self , Nested :: Body ( body) ) ;
571
558
}
572
559
hir:: ItemKind :: Macro ( ref macro_def, _) => {
573
- self . print_mac_def ( macro_def, & item. ident , item. span , |state| {
574
- state. print_visibility ( & item. vis )
575
- } ) ;
560
+ self . print_mac_def ( macro_def, & item. ident , item. span , |_| { } ) ;
576
561
}
577
562
hir:: ItemKind :: Mod ( ref _mod) => {
578
- self . head ( visibility_qualified ( & item . vis , "mod" ) ) ;
563
+ self . head ( "mod" ) ;
579
564
self . print_ident ( item. ident ) ;
580
565
self . nbsp ( ) ;
581
566
self . bopen ( ) ;
@@ -593,7 +578,7 @@ impl<'a> State<'a> {
593
578
self . bclose ( item. span ) ;
594
579
}
595
580
hir:: ItemKind :: GlobalAsm ( ref asm) => {
596
- self . head ( visibility_qualified ( & item . vis , "global_asm!" ) ) ;
581
+ self . head ( "global_asm!" ) ;
597
582
self . print_inline_asm ( asm) ;
598
583
self . end ( )
599
584
}
@@ -619,14 +604,14 @@ impl<'a> State<'a> {
619
604
} ) ;
620
605
}
621
606
hir:: ItemKind :: Enum ( ref enum_definition, ref params) => {
622
- self . print_enum_def ( enum_definition, params, item. ident . name , item. span , & item . vis ) ;
607
+ self . print_enum_def ( enum_definition, params, item. ident . name , item. span ) ;
623
608
}
624
609
hir:: ItemKind :: Struct ( ref struct_def, ref generics) => {
625
- self . head ( visibility_qualified ( & item . vis , "struct" ) ) ;
610
+ self . head ( "struct" ) ;
626
611
self . print_struct ( struct_def, generics, item. ident . name , item. span , true ) ;
627
612
}
628
613
hir:: ItemKind :: Union ( ref struct_def, ref generics) => {
629
- self . head ( visibility_qualified ( & item . vis , "union" ) ) ;
614
+ self . head ( "union" ) ;
630
615
self . print_struct ( struct_def, generics, item. ident . name , item. span , true ) ;
631
616
}
632
617
hir:: ItemKind :: Impl ( hir:: Impl {
@@ -641,7 +626,6 @@ impl<'a> State<'a> {
641
626
items,
642
627
} ) => {
643
628
self . head ( "" ) ;
644
- self . print_visibility ( & item. vis ) ;
645
629
self . print_defaultness ( defaultness) ;
646
630
self . print_unsafety ( unsafety) ;
647
631
self . word_nbsp ( "impl" ) ;
@@ -678,7 +662,6 @@ impl<'a> State<'a> {
678
662
}
679
663
hir:: ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, trait_items) => {
680
664
self . head ( "" ) ;
681
- self . print_visibility ( & item. vis ) ;
682
665
self . print_is_auto ( is_auto) ;
683
666
self . print_unsafety ( unsafety) ;
684
667
self . word_nbsp ( "trait" ) ;
@@ -704,7 +687,7 @@ impl<'a> State<'a> {
704
687
self . bclose ( item. span ) ;
705
688
}
706
689
hir:: ItemKind :: TraitAlias ( ref generics, ref bounds) => {
707
- self . head ( visibility_qualified ( & item . vis , "trait" ) ) ;
690
+ self . head ( "trait" ) ;
708
691
self . print_ident ( item. ident ) ;
709
692
self . print_generic_params ( & generics. params ) ;
710
693
let mut real_bounds = Vec :: with_capacity ( bounds. len ( ) ) ;
@@ -752,9 +735,8 @@ impl<'a> State<'a> {
752
735
generics : & hir:: Generics < ' _ > ,
753
736
name : Symbol ,
754
737
span : rustc_span:: Span ,
755
- visibility : & hir:: Visibility < ' _ > ,
756
738
) {
757
- self . head ( visibility_qualified ( visibility , "enum" ) ) ;
739
+ self . head ( "enum" ) ;
758
740
self . print_name ( name) ;
759
741
self . print_generic_params ( & generics. params ) ;
760
742
self . print_where_clause ( & generics. where_clause ) ;
@@ -777,27 +759,6 @@ impl<'a> State<'a> {
777
759
self . bclose ( span)
778
760
}
779
761
780
- pub fn print_visibility ( & mut self , vis : & hir:: Visibility < ' _ > ) {
781
- match vis. node {
782
- hir:: VisibilityKind :: Public => self . word_nbsp ( "pub" ) ,
783
- hir:: VisibilityKind :: Crate ( ast:: CrateSugar :: JustCrate ) => self . word_nbsp ( "crate" ) ,
784
- hir:: VisibilityKind :: Crate ( ast:: CrateSugar :: PubCrate ) => self . word_nbsp ( "pub(crate)" ) ,
785
- hir:: VisibilityKind :: Restricted { ref path, .. } => {
786
- self . word ( "pub(" ) ;
787
- if path. segments . len ( ) == 1 && path. segments [ 0 ] . ident . name == kw:: Super {
788
- // Special case: `super` can print like `pub(super)`.
789
- self . word ( "super" ) ;
790
- } else {
791
- // Everything else requires `in` at present.
792
- self . word_nbsp ( "in" ) ;
793
- self . print_path ( path, false ) ;
794
- }
795
- self . word_nbsp ( ")" ) ;
796
- }
797
- hir:: VisibilityKind :: Inherited => ( ) ,
798
- }
799
- }
800
-
801
762
pub fn print_defaultness ( & mut self , defaultness : hir:: Defaultness ) {
802
763
match defaultness {
803
764
hir:: Defaultness :: Default { .. } => self . word_nbsp ( "default" ) ,
@@ -822,7 +783,6 @@ impl<'a> State<'a> {
822
783
self . commasep ( Inconsistent , struct_def. fields ( ) , |s, field| {
823
784
s. maybe_print_comment ( field. span . lo ( ) ) ;
824
785
s. print_outer_attributes ( s. attrs ( field. hir_id ) ) ;
825
- s. print_visibility ( & field. vis ) ;
826
786
s. print_type ( & field. ty )
827
787
} ) ;
828
788
self . pclose ( ) ;
@@ -844,7 +804,6 @@ impl<'a> State<'a> {
844
804
self . hardbreak_if_not_bol ( ) ;
845
805
self . maybe_print_comment ( field. span . lo ( ) ) ;
846
806
self . print_outer_attributes ( self . attrs ( field. hir_id ) ) ;
847
- self . print_visibility ( & field. vis ) ;
848
807
self . print_ident ( field. ident ) ;
849
808
self . word_nbsp ( ":" ) ;
850
809
self . print_type ( & field. ty ) ;
@@ -871,11 +830,10 @@ impl<'a> State<'a> {
871
830
ident : Ident ,
872
831
m : & hir:: FnSig < ' _ > ,
873
832
generics : & hir:: Generics < ' _ > ,
874
- vis : & hir:: Visibility < ' _ > ,
875
833
arg_names : & [ Ident ] ,
876
834
body_id : Option < hir:: BodyId > ,
877
835
) {
878
- self . print_fn ( & m. decl , m. header , Some ( ident. name ) , generics, vis , arg_names, body_id)
836
+ self . print_fn ( & m. decl , m. header , Some ( ident. name ) , generics, arg_names, body_id)
879
837
}
880
838
881
839
pub fn print_trait_item ( & mut self , ti : & hir:: TraitItem < ' _ > ) {
@@ -885,21 +843,15 @@ impl<'a> State<'a> {
885
843
self . print_outer_attributes ( self . attrs ( ti. hir_id ( ) ) ) ;
886
844
match ti. kind {
887
845
hir:: TraitItemKind :: Const ( ref ty, default) => {
888
- let vis =
889
- Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ;
890
- self . print_associated_const ( ti. ident , & ty, default, & vis) ;
846
+ self . print_associated_const ( ti. ident , & ty, default) ;
891
847
}
892
848
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Required ( ref arg_names) ) => {
893
- let vis =
894
- Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ;
895
- self . print_method_sig ( ti. ident , sig, & ti. generics , & vis, arg_names, None ) ;
849
+ self . print_method_sig ( ti. ident , sig, & ti. generics , arg_names, None ) ;
896
850
self . word ( ";" ) ;
897
851
}
898
852
hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
899
- let vis =
900
- Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ;
901
853
self . head ( "" ) ;
902
- self . print_method_sig ( ti. ident , sig, & ti. generics , & vis , & [ ] , Some ( body) ) ;
854
+ self . print_method_sig ( ti. ident , sig, & ti. generics , & [ ] , Some ( body) ) ;
903
855
self . nbsp ( ) ;
904
856
self . end ( ) ; // need to close a box
905
857
self . end ( ) ; // need to close a box
@@ -925,11 +877,11 @@ impl<'a> State<'a> {
925
877
926
878
match ii. kind {
927
879
hir:: ImplItemKind :: Const ( ref ty, expr) => {
928
- self . print_associated_const ( ii. ident , & ty, Some ( expr) , & ii . vis ) ;
880
+ self . print_associated_const ( ii. ident , & ty, Some ( expr) ) ;
929
881
}
930
882
hir:: ImplItemKind :: Fn ( ref sig, body) => {
931
883
self . head ( "" ) ;
932
- self . print_method_sig ( ii. ident , sig, & ii. generics , & ii . vis , & [ ] , Some ( body) ) ;
884
+ self . print_method_sig ( ii. ident , sig, & ii. generics , & [ ] , Some ( body) ) ;
933
885
self . nbsp ( ) ;
934
886
self . end ( ) ; // need to close a box
935
887
self . end ( ) ; // need to close a box
@@ -2007,11 +1959,10 @@ impl<'a> State<'a> {
2007
1959
header : hir:: FnHeader ,
2008
1960
name : Option < Symbol > ,
2009
1961
generics : & hir:: Generics < ' _ > ,
2010
- vis : & hir:: Visibility < ' _ > ,
2011
1962
arg_names : & [ Ident ] ,
2012
1963
body_id : Option < hir:: BodyId > ,
2013
1964
) {
2014
- self . print_fn_header_info ( header, vis ) ;
1965
+ self . print_fn_header_info ( header) ;
2015
1966
2016
1967
if let Some ( name) = name {
2017
1968
self . nbsp ( ) ;
@@ -2300,16 +2251,13 @@ impl<'a> State<'a> {
2300
2251
} ,
2301
2252
name,
2302
2253
& generics,
2303
- & Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ,
2304
2254
arg_names,
2305
2255
None ,
2306
2256
) ;
2307
2257
self . end ( ) ;
2308
2258
}
2309
2259
2310
- pub fn print_fn_header_info ( & mut self , header : hir:: FnHeader , vis : & hir:: Visibility < ' _ > ) {
2311
- self . word ( visibility_qualified ( vis, "" ) ) ;
2312
-
2260
+ pub fn print_fn_header_info ( & mut self , header : hir:: FnHeader ) {
2313
2261
match header. constness {
2314
2262
hir:: Constness :: NotConst => { }
2315
2263
hir:: Constness :: Const => self . word_nbsp ( "const" ) ,
0 commit comments