@@ -746,33 +746,21 @@ impl Item {
746746 Some ( tcx. visibility ( def_id) )
747747 }
748748
749- fn attributes_without_repr ( & self , tcx : TyCtxt < ' _ > , is_json : bool ) -> Vec < String > {
749+ /// Get a list of attributes excluding `#[repr]`.
750+ ///
751+ /// Only used by the HTML output-format.
752+ fn attributes_without_repr ( & self , tcx : TyCtxt < ' _ > ) -> Vec < String > {
750753 const ALLOWED_ATTRIBUTES : & [ Symbol ] =
751- & [ sym:: export_name, sym:: link_section, sym:: no_mangle , sym :: non_exhaustive] ;
754+ & [ sym:: export_name, sym:: link_section, sym:: non_exhaustive] ;
752755 self . attrs
753756 . other_attrs
754757 . iter ( )
755758 . filter_map ( |attr| {
756- // NoMangle is special-cased because cargo-semver-checks uses it
757- if matches ! ( attr, hir:: Attribute :: Parsed ( AttributeKind :: NoMangle ( ..) ) ) {
759+ if matches ! ( attr, hir:: Attribute :: Parsed ( AttributeKind :: NoMangle ( _) ) ) {
758760 Some ( "#[no_mangle]" . to_string ( ) )
759- } else if is_json {
760- match attr {
761- // rustdoc-json stores this in `Item::deprecation`, so we
762- // don't want it it `Item::attrs`.
763- hir:: Attribute :: Parsed ( AttributeKind :: Deprecation { .. } ) => None ,
764- // We have separate pretty-printing logic for `#[repr(..)]` attributes.
765- hir:: Attribute :: Parsed ( AttributeKind :: Repr ( ..) ) => None ,
766- _ => Some ( {
767- let mut s = rustc_hir_pretty:: attribute_to_string ( & tcx, attr) ;
768- assert_eq ! ( s. pop( ) , Some ( '\n' ) ) ;
769- s
770- } ) ,
771- }
761+ } else if !attr. has_any_name ( ALLOWED_ATTRIBUTES ) {
762+ None
772763 } else {
773- if !attr. has_any_name ( ALLOWED_ATTRIBUTES ) {
774- return None ;
775- }
776764 Some (
777765 rustc_hir_pretty:: attribute_to_string ( & tcx, attr)
778766 . replace ( "\\ \n " , "" )
@@ -784,18 +772,23 @@ impl Item {
784772 . collect ( )
785773 }
786774
787- pub ( crate ) fn attributes ( & self , tcx : TyCtxt < ' _ > , cache : & Cache , is_json : bool ) -> Vec < String > {
788- let mut attrs = self . attributes_without_repr ( tcx, is_json) ;
775+ /// Get a list of attributes to display on this item.
776+ ///
777+ /// Only used by the HTML output-format.
778+ pub ( crate ) fn attributes ( & self , tcx : TyCtxt < ' _ > , cache : & Cache ) -> Vec < String > {
779+ let mut attrs = self . attributes_without_repr ( tcx) ;
789780
790- if let Some ( repr_attr) = self . repr ( tcx, cache, is_json ) {
781+ if let Some ( repr_attr) = self . repr ( tcx, cache) {
791782 attrs. push ( repr_attr) ;
792783 }
793784 attrs
794785 }
795786
796787 /// Returns a stringified `#[repr(...)]` attribute.
797- pub ( crate ) fn repr ( & self , tcx : TyCtxt < ' _ > , cache : & Cache , is_json : bool ) -> Option < String > {
798- repr_attributes ( tcx, cache, self . def_id ( ) ?, self . type_ ( ) , is_json)
788+ ///
789+ /// Only used by the HTML output-format.
790+ pub ( crate ) fn repr ( & self , tcx : TyCtxt < ' _ > , cache : & Cache ) -> Option < String > {
791+ repr_attributes ( tcx, cache, self . def_id ( ) ?, self . type_ ( ) )
799792 }
800793
801794 pub fn is_doc_hidden ( & self ) -> bool {
@@ -807,12 +800,14 @@ impl Item {
807800 }
808801}
809802
803+ /// Return a string representing the `#[repr]` attribute if present.
804+ ///
805+ /// Only used by the HTML output-format.
810806pub ( crate ) fn repr_attributes (
811807 tcx : TyCtxt < ' _ > ,
812808 cache : & Cache ,
813809 def_id : DefId ,
814810 item_type : ItemType ,
815- is_json : bool ,
816811) -> Option < String > {
817812 use rustc_abi:: IntegerType ;
818813
@@ -829,7 +824,6 @@ pub(crate) fn repr_attributes(
829824 // Render `repr(transparent)` iff the non-1-ZST field is public or at least one
830825 // field is public in case all fields are 1-ZST fields.
831826 let render_transparent = cache. document_private
832- || is_json
833827 || adt
834828 . all_fields ( )
835829 . find ( |field| {
0 commit comments