@@ -909,10 +909,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
909909 AssocTypeItem ( bounds, default)
910910 }
911911 } ;
912- let what_rustc_thinks =
913- Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx) ;
914- // Trait items always inherit the trait's visibility -- we don't want to show `pub`.
915- Item { visibility : Inherited , ..what_rustc_thinks }
912+ Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx)
916913 } )
917914 }
918915}
@@ -948,20 +945,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
948945 }
949946 } ;
950947
951- let what_rustc_thinks =
952- Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx) ;
953- let parent_item = cx. tcx . hir ( ) . expect_item ( cx. tcx . hir ( ) . get_parent_did ( self . hir_id ( ) ) ) ;
954- if let hir:: ItemKind :: Impl ( impl_) = & parent_item. kind {
955- if impl_. of_trait . is_some ( ) {
956- // Trait impl items always inherit the impl's visibility --
957- // we don't want to show `pub`.
958- Item { visibility : Inherited , ..what_rustc_thinks }
959- } else {
960- what_rustc_thinks
961- }
962- } else {
963- panic ! ( "found impl item with non-impl parent {:?}" , parent_item) ;
964- }
948+ Item :: from_def_id_and_parts ( local_did, Some ( self . ident . name ) , inner, cx)
965949 } )
966950 }
967951}
@@ -1570,14 +1554,7 @@ impl Clean<Item> for ty::FieldDef {
15701554}
15711555
15721556fn clean_field ( def_id : DefId , name : Symbol , ty : Type , cx : & mut DocContext < ' _ > ) -> Item {
1573- let what_rustc_thinks =
1574- Item :: from_def_id_and_parts ( def_id, Some ( name) , StructFieldItem ( ty) , cx) ;
1575- if is_field_vis_inherited ( cx. tcx , def_id) {
1576- // Variant fields inherit their enum's visibility.
1577- Item { visibility : Visibility :: Inherited , ..what_rustc_thinks }
1578- } else {
1579- what_rustc_thinks
1580- }
1557+ Item :: from_def_id_and_parts ( def_id, Some ( name) , StructFieldItem ( ty) , cx)
15811558}
15821559
15831560fn is_field_vis_inherited ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
@@ -1592,17 +1569,21 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
15921569 }
15931570}
15941571
1572+ fn clean_vis ( vis : ty:: Visibility ) -> Visibility {
1573+ match vis {
1574+ ty:: Visibility :: Public => Visibility :: Public ,
1575+ // NOTE: this is not quite right: `ty` uses `Invisible` to mean 'private',
1576+ // while rustdoc really does mean inherited. That means that for enum variants, such as
1577+ // `pub enum E { V }`, `V` will be marked as `Public` by `ty`, but as `Inherited` by rustdoc.
1578+ // `Item::visibility()` overrides `tcx.visibility` explicitly to make sure this distinction is captured.
1579+ ty:: Visibility :: Invisible => Visibility :: Inherited ,
1580+ ty:: Visibility :: Restricted ( module) => Visibility :: Restricted ( module) ,
1581+ }
1582+ }
1583+
15951584impl Clean < Visibility > for ty:: Visibility {
15961585 fn clean ( & self , _cx : & mut DocContext < ' _ > ) -> Visibility {
1597- match * self {
1598- ty:: Visibility :: Public => Visibility :: Public ,
1599- // NOTE: this is not quite right: `ty` uses `Invisible` to mean 'private',
1600- // while rustdoc really does mean inherited. That means that for enum variants, such as
1601- // `pub enum E { V }`, `V` will be marked as `Public` by `ty`, but as `Inherited` by rustdoc.
1602- // Various parts of clean override `tcx.visibility` explicitly to make sure this distinction is captured.
1603- ty:: Visibility :: Invisible => Visibility :: Inherited ,
1604- ty:: Visibility :: Restricted ( module) => Visibility :: Restricted ( module) ,
1605- }
1586+ clean_vis ( * self )
16061587 }
16071588}
16081589
@@ -1635,10 +1616,7 @@ impl Clean<Item> for ty::VariantDef {
16351616 fields : self . fields . iter ( ) . map ( |field| field. clean ( cx) ) . collect ( ) ,
16361617 } ) ,
16371618 } ;
1638- let what_rustc_thinks =
1639- Item :: from_def_id_and_parts ( self . def_id , Some ( self . ident . name ) , VariantItem ( kind) , cx) ;
1640- // don't show `pub` for variants, which always inherit visibility
1641- Item { visibility : Inherited , ..what_rustc_thinks }
1619+ Item :: from_def_id_and_parts ( self . def_id , Some ( self . ident . name ) , VariantItem ( kind) , cx)
16421620 }
16431621}
16441622
@@ -1798,10 +1776,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
17981776impl Clean < Item > for hir:: Variant < ' _ > {
17991777 fn clean ( & self , cx : & mut DocContext < ' _ > ) -> Item {
18001778 let kind = VariantItem ( self . data . clean ( cx) ) ;
1801- let what_rustc_thinks =
1802- Item :: from_hir_id_and_parts ( self . id , Some ( self . ident . name ) , kind, cx) ;
1803- // don't show `pub` for variants, which are always public
1804- Item { visibility : Inherited , ..what_rustc_thinks }
1779+ Item :: from_hir_id_and_parts ( self . id , Some ( self . ident . name ) , kind, cx)
18051780 }
18061781}
18071782
@@ -1887,9 +1862,9 @@ fn clean_extern_crate(
18871862 name: Some ( name) ,
18881863 attrs: box attrs. clean( cx) ,
18891864 def_id: crate_def_id. into( ) ,
1890- visibility: ty_vis. clean( cx) ,
1891- kind: box ExternCrateItem { src: orig_name } ,
1865+ kind: box ExternCrateItem { src: orig_name, crate_stmt_id: krate. def_id } ,
18921866 cfg: attrs. cfg( cx. tcx, & cx. cache. hidden_cfg) ,
1867+ inline_stmt_id: None ,
18931868 } ]
18941869}
18951870
0 commit comments