@@ -8,12 +8,11 @@ use rustc_ast_pretty::pprust::{Comments, PrintState};
88use rustc_hir as hir;
99use rustc_hir:: { GenericArg , GenericParam , GenericParamKind , Node , Term } ;
1010use rustc_hir:: { GenericBound , PatKind , RangeEnd , TraitBoundModifier } ;
11- use rustc_span:: source_map:: { SourceMap , Spanned } ;
11+ use rustc_span:: source_map:: SourceMap ;
1212use rustc_span:: symbol:: { kw, Ident , IdentPrinter , Symbol } ;
1313use rustc_span:: { self , FileName } ;
1414use rustc_target:: spec:: abi:: Abi ;
1515
16- use std:: borrow:: Cow ;
1716use std:: cell:: Cell ;
1817use std:: vec;
1918
@@ -190,13 +189,6 @@ where
190189 printer. s . eof ( )
191190}
192191
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-
200192pub fn generic_params_to_string ( generic_params : & [ GenericParam < ' _ > ] ) -> String {
201193 to_string ( NO_ANN , |s| s. print_generic_params ( generic_params) )
202194}
@@ -222,21 +214,19 @@ pub fn fn_to_string(
222214 header : hir:: FnHeader ,
223215 name : Option < Symbol > ,
224216 generics : & hir:: Generics < ' _ > ,
225- vis : & hir:: Visibility < ' _ > ,
226217 arg_names : & [ Ident ] ,
227218 body_id : Option < hir:: BodyId > ,
228219) -> 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) )
230221}
231222
232223pub fn enum_def_to_string (
233224 enum_definition : & hir:: EnumDef < ' _ > ,
234225 generics : & hir:: Generics < ' _ > ,
235226 name : Symbol ,
236227 span : rustc_span:: Span ,
237- visibility : & hir:: Visibility < ' _ > ,
238228) -> 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) )
240230}
241231
242232impl < ' a > State < ' a > {
@@ -394,7 +384,6 @@ impl<'a> State<'a> {
394384 } ,
395385 Some ( item. ident . name ) ,
396386 generics,
397- & item. vis ,
398387 arg_names,
399388 None ,
400389 ) ;
@@ -403,7 +392,7 @@ impl<'a> State<'a> {
403392 self . end ( ) // end the outer fn box
404393 }
405394 hir:: ForeignItemKind :: Static ( ref t, m) => {
406- self . head ( visibility_qualified ( & item . vis , "static" ) ) ;
395+ self . head ( "static" ) ;
407396 if m == hir:: Mutability :: Mut {
408397 self . word_space ( "mut" ) ;
409398 }
@@ -415,7 +404,7 @@ impl<'a> State<'a> {
415404 self . end ( ) // end the outer cbox
416405 }
417406 hir:: ForeignItemKind :: Type => {
418- self . head ( visibility_qualified ( & item . vis , "type" ) ) ;
407+ self . head ( "type" ) ;
419408 self . print_ident ( item. ident ) ;
420409 self . word ( ";" ) ;
421410 self . end ( ) ; // end the head-ibox
@@ -429,9 +418,8 @@ impl<'a> State<'a> {
429418 ident : Ident ,
430419 ty : & hir:: Ty < ' _ > ,
431420 default : Option < hir:: BodyId > ,
432- vis : & hir:: Visibility < ' _ > ,
433421 ) {
434- self . word ( visibility_qualified ( vis , "" ) ) ;
422+ self . head ( "" ) ;
435423 self . word_space ( "const" ) ;
436424 self . print_ident ( ident) ;
437425 self . word_space ( ":" ) ;
@@ -472,7 +460,7 @@ impl<'a> State<'a> {
472460 generics : & hir:: Generics < ' _ > ,
473461 inner : impl Fn ( & mut Self ) ,
474462 ) {
475- self . head ( visibility_qualified ( & item . vis , "type" ) ) ;
463+ self . head ( "type" ) ;
476464 self . print_ident ( item. ident ) ;
477465 self . print_generic_params ( & generics. params ) ;
478466 self . end ( ) ; // end the inner ibox
@@ -493,7 +481,7 @@ impl<'a> State<'a> {
493481 self . ann . pre ( self , AnnNode :: Item ( item) ) ;
494482 match item. kind {
495483 hir:: ItemKind :: ExternCrate ( orig_name) => {
496- self . head ( visibility_qualified ( & item . vis , "extern crate" ) ) ;
484+ self . head ( "extern crate" ) ;
497485 if let Some ( orig_name) = orig_name {
498486 self . print_name ( orig_name) ;
499487 self . space ( ) ;
@@ -506,7 +494,7 @@ impl<'a> State<'a> {
506494 self . end ( ) ; // end outer head-block
507495 }
508496 hir:: ItemKind :: Use ( ref path, kind) => {
509- self . head ( visibility_qualified ( & item . vis , "use" ) ) ;
497+ self . head ( "use" ) ;
510498 self . print_path ( path, false ) ;
511499
512500 match kind {
@@ -525,7 +513,7 @@ impl<'a> State<'a> {
525513 self . end ( ) ; // end outer head-block
526514 }
527515 hir:: ItemKind :: Static ( ref ty, m, expr) => {
528- self . head ( visibility_qualified ( & item . vis , "static" ) ) ;
516+ self . head ( "static" ) ;
529517 if m == hir:: Mutability :: Mut {
530518 self . word_space ( "mut" ) ;
531519 }
@@ -541,7 +529,7 @@ impl<'a> State<'a> {
541529 self . end ( ) ; // end the outer cbox
542530 }
543531 hir:: ItemKind :: Const ( ref ty, expr) => {
544- self . head ( visibility_qualified ( & item . vis , "const" ) ) ;
532+ self . head ( "const" ) ;
545533 self . print_ident ( item. ident ) ;
546534 self . word_space ( ":" ) ;
547535 self . print_type ( & ty) ;
@@ -560,7 +548,6 @@ impl<'a> State<'a> {
560548 sig. header ,
561549 Some ( item. ident . name ) ,
562550 param_names,
563- & item. vis ,
564551 & [ ] ,
565552 Some ( body) ,
566553 ) ;
@@ -570,12 +557,10 @@ impl<'a> State<'a> {
570557 self . ann . nested ( self , Nested :: Body ( body) ) ;
571558 }
572559 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 , |_| { } ) ;
576561 }
577562 hir:: ItemKind :: Mod ( ref _mod) => {
578- self . head ( visibility_qualified ( & item . vis , "mod" ) ) ;
563+ self . head ( "mod" ) ;
579564 self . print_ident ( item. ident ) ;
580565 self . nbsp ( ) ;
581566 self . bopen ( ) ;
@@ -593,7 +578,7 @@ impl<'a> State<'a> {
593578 self . bclose ( item. span ) ;
594579 }
595580 hir:: ItemKind :: GlobalAsm ( ref asm) => {
596- self . head ( visibility_qualified ( & item . vis , "global_asm!" ) ) ;
581+ self . head ( "global_asm!" ) ;
597582 self . print_inline_asm ( asm) ;
598583 self . end ( )
599584 }
@@ -619,14 +604,14 @@ impl<'a> State<'a> {
619604 } ) ;
620605 }
621606 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 ) ;
623608 }
624609 hir:: ItemKind :: Struct ( ref struct_def, ref generics) => {
625- self . head ( visibility_qualified ( & item . vis , "struct" ) ) ;
610+ self . head ( "struct" ) ;
626611 self . print_struct ( struct_def, generics, item. ident . name , item. span , true ) ;
627612 }
628613 hir:: ItemKind :: Union ( ref struct_def, ref generics) => {
629- self . head ( visibility_qualified ( & item . vis , "union" ) ) ;
614+ self . head ( "union" ) ;
630615 self . print_struct ( struct_def, generics, item. ident . name , item. span , true ) ;
631616 }
632617 hir:: ItemKind :: Impl ( hir:: Impl {
@@ -641,7 +626,6 @@ impl<'a> State<'a> {
641626 items,
642627 } ) => {
643628 self . head ( "" ) ;
644- self . print_visibility ( & item. vis ) ;
645629 self . print_defaultness ( defaultness) ;
646630 self . print_unsafety ( unsafety) ;
647631 self . word_nbsp ( "impl" ) ;
@@ -678,7 +662,6 @@ impl<'a> State<'a> {
678662 }
679663 hir:: ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, trait_items) => {
680664 self . head ( "" ) ;
681- self . print_visibility ( & item. vis ) ;
682665 self . print_is_auto ( is_auto) ;
683666 self . print_unsafety ( unsafety) ;
684667 self . word_nbsp ( "trait" ) ;
@@ -704,7 +687,7 @@ impl<'a> State<'a> {
704687 self . bclose ( item. span ) ;
705688 }
706689 hir:: ItemKind :: TraitAlias ( ref generics, ref bounds) => {
707- self . head ( visibility_qualified ( & item . vis , "trait" ) ) ;
690+ self . head ( "trait" ) ;
708691 self . print_ident ( item. ident ) ;
709692 self . print_generic_params ( & generics. params ) ;
710693 let mut real_bounds = Vec :: with_capacity ( bounds. len ( ) ) ;
@@ -752,9 +735,8 @@ impl<'a> State<'a> {
752735 generics : & hir:: Generics < ' _ > ,
753736 name : Symbol ,
754737 span : rustc_span:: Span ,
755- visibility : & hir:: Visibility < ' _ > ,
756738 ) {
757- self . head ( visibility_qualified ( visibility , "enum" ) ) ;
739+ self . head ( "enum" ) ;
758740 self . print_name ( name) ;
759741 self . print_generic_params ( & generics. params ) ;
760742 self . print_where_clause ( & generics. where_clause ) ;
@@ -777,27 +759,6 @@ impl<'a> State<'a> {
777759 self . bclose ( span)
778760 }
779761
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-
801762 pub fn print_defaultness ( & mut self , defaultness : hir:: Defaultness ) {
802763 match defaultness {
803764 hir:: Defaultness :: Default { .. } => self . word_nbsp ( "default" ) ,
@@ -822,7 +783,6 @@ impl<'a> State<'a> {
822783 self . commasep ( Inconsistent , struct_def. fields ( ) , |s, field| {
823784 s. maybe_print_comment ( field. span . lo ( ) ) ;
824785 s. print_outer_attributes ( s. attrs ( field. hir_id ) ) ;
825- s. print_visibility ( & field. vis ) ;
826786 s. print_type ( & field. ty )
827787 } ) ;
828788 self . pclose ( ) ;
@@ -844,7 +804,6 @@ impl<'a> State<'a> {
844804 self . hardbreak_if_not_bol ( ) ;
845805 self . maybe_print_comment ( field. span . lo ( ) ) ;
846806 self . print_outer_attributes ( self . attrs ( field. hir_id ) ) ;
847- self . print_visibility ( & field. vis ) ;
848807 self . print_ident ( field. ident ) ;
849808 self . word_nbsp ( ":" ) ;
850809 self . print_type ( & field. ty ) ;
@@ -871,11 +830,10 @@ impl<'a> State<'a> {
871830 ident : Ident ,
872831 m : & hir:: FnSig < ' _ > ,
873832 generics : & hir:: Generics < ' _ > ,
874- vis : & hir:: Visibility < ' _ > ,
875833 arg_names : & [ Ident ] ,
876834 body_id : Option < hir:: BodyId > ,
877835 ) {
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)
879837 }
880838
881839 pub fn print_trait_item ( & mut self , ti : & hir:: TraitItem < ' _ > ) {
@@ -885,21 +843,15 @@ impl<'a> State<'a> {
885843 self . print_outer_attributes ( self . attrs ( ti. hir_id ( ) ) ) ;
886844 match ti. kind {
887845 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) ;
891847 }
892848 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 ) ;
896850 self . word ( ";" ) ;
897851 }
898852 hir:: TraitItemKind :: Fn ( ref sig, hir:: TraitFn :: Provided ( body) ) => {
899- let vis =
900- Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ;
901853 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) ) ;
903855 self . nbsp ( ) ;
904856 self . end ( ) ; // need to close a box
905857 self . end ( ) ; // need to close a box
@@ -925,11 +877,11 @@ impl<'a> State<'a> {
925877
926878 match ii. kind {
927879 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) ) ;
929881 }
930882 hir:: ImplItemKind :: Fn ( ref sig, body) => {
931883 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) ) ;
933885 self . nbsp ( ) ;
934886 self . end ( ) ; // need to close a box
935887 self . end ( ) ; // need to close a box
@@ -2007,11 +1959,10 @@ impl<'a> State<'a> {
20071959 header : hir:: FnHeader ,
20081960 name : Option < Symbol > ,
20091961 generics : & hir:: Generics < ' _ > ,
2010- vis : & hir:: Visibility < ' _ > ,
20111962 arg_names : & [ Ident ] ,
20121963 body_id : Option < hir:: BodyId > ,
20131964 ) {
2014- self . print_fn_header_info ( header, vis ) ;
1965+ self . print_fn_header_info ( header) ;
20151966
20161967 if let Some ( name) = name {
20171968 self . nbsp ( ) ;
@@ -2300,16 +2251,13 @@ impl<'a> State<'a> {
23002251 } ,
23012252 name,
23022253 & generics,
2303- & Spanned { span : rustc_span:: DUMMY_SP , node : hir:: VisibilityKind :: Inherited } ,
23042254 arg_names,
23052255 None ,
23062256 ) ;
23072257 self . end ( ) ;
23082258 }
23092259
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 ) {
23132261 match header. constness {
23142262 hir:: Constness :: NotConst => { }
23152263 hir:: Constness :: Const => self . word_nbsp ( "const" ) ,
0 commit comments