@@ -746,33 +746,21 @@ impl Item {
746
746
Some ( tcx. visibility ( def_id) )
747
747
}
748
748
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 > {
750
753
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] ;
752
755
self . attrs
753
756
. other_attrs
754
757
. iter ( )
755
758
. 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 ( _) ) ) {
758
760
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
772
763
} else {
773
- if !attr. has_any_name ( ALLOWED_ATTRIBUTES ) {
774
- return None ;
775
- }
776
764
Some (
777
765
rustc_hir_pretty:: attribute_to_string ( & tcx, attr)
778
766
. replace ( "\\ \n " , "" )
@@ -784,18 +772,23 @@ impl Item {
784
772
. collect ( )
785
773
}
786
774
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) ;
789
780
790
- if let Some ( repr_attr) = self . repr ( tcx, cache, is_json ) {
781
+ if let Some ( repr_attr) = self . repr ( tcx, cache) {
791
782
attrs. push ( repr_attr) ;
792
783
}
793
784
attrs
794
785
}
795
786
796
787
/// 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_ ( ) )
799
792
}
800
793
801
794
pub fn is_doc_hidden ( & self ) -> bool {
@@ -807,12 +800,14 @@ impl Item {
807
800
}
808
801
}
809
802
803
+ /// Return a string representing the `#[repr]` attribute if present.
804
+ ///
805
+ /// Only used by the HTML output-format.
810
806
pub ( crate ) fn repr_attributes (
811
807
tcx : TyCtxt < ' _ > ,
812
808
cache : & Cache ,
813
809
def_id : DefId ,
814
810
item_type : ItemType ,
815
- is_json : bool ,
816
811
) -> Option < String > {
817
812
use rustc_abi:: IntegerType ;
818
813
@@ -829,7 +824,6 @@ pub(crate) fn repr_attributes(
829
824
// Render `repr(transparent)` iff the non-1-ZST field is public or at least one
830
825
// field is public in case all fields are 1-ZST fields.
831
826
let render_transparent = cache. document_private
832
- || is_json
833
827
|| adt
834
828
. all_fields ( )
835
829
. find ( |field| {
0 commit comments