@@ -909,10 +909,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
909
909
AssocTypeItem ( bounds, default)
910
910
}
911
911
} ;
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)
916
913
} )
917
914
}
918
915
}
@@ -948,20 +945,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
948
945
}
949
946
} ;
950
947
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)
965
949
} )
966
950
}
967
951
}
@@ -1570,14 +1554,7 @@ impl Clean<Item> for ty::FieldDef {
1570
1554
}
1571
1555
1572
1556
fn 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)
1581
1558
}
1582
1559
1583
1560
fn 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 {
1592
1569
}
1593
1570
}
1594
1571
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
+
1595
1584
impl Clean < Visibility > for ty:: Visibility {
1596
1585
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 )
1606
1587
}
1607
1588
}
1608
1589
@@ -1635,10 +1616,7 @@ impl Clean<Item> for ty::VariantDef {
1635
1616
fields : self . fields . iter ( ) . map ( |field| field. clean ( cx) ) . collect ( ) ,
1636
1617
} ) ,
1637
1618
} ;
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)
1642
1620
}
1643
1621
}
1644
1622
@@ -1798,10 +1776,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
1798
1776
impl Clean < Item > for hir:: Variant < ' _ > {
1799
1777
fn clean ( & self , cx : & mut DocContext < ' _ > ) -> Item {
1800
1778
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)
1805
1780
}
1806
1781
}
1807
1782
@@ -1887,9 +1862,9 @@ fn clean_extern_crate(
1887
1862
name: Some ( name) ,
1888
1863
attrs: box attrs. clean( cx) ,
1889
1864
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 } ,
1892
1866
cfg: attrs. cfg( cx. tcx, & cx. cache. hidden_cfg) ,
1867
+ inline_stmt_id: None ,
1893
1868
} ]
1894
1869
}
1895
1870
0 commit comments