@@ -14,7 +14,7 @@ use rustc_attr as attr;
1414use  rustc_data_structures:: fx:: { FxHashMap ,  FxHashSet } ; 
1515use  rustc_hir as  hir; 
1616use  rustc_hir:: def:: { CtorKind ,  DefKind ,  Res } ; 
17- use  rustc_hir:: def_id:: { CrateNum ,  DefId ,  CRATE_DEF_INDEX } ; 
17+ use  rustc_hir:: def_id:: { CrateNum ,  DefId ,  CRATE_DEF_INDEX ,   LOCAL_CRATE } ; 
1818use  rustc_index:: vec:: { Idx ,  IndexVec } ; 
1919use  rustc_infer:: infer:: region_constraints:: { Constraint ,  RegionConstraintData } ; 
2020use  rustc_middle:: bug; 
@@ -229,7 +229,6 @@ impl Clean<Item> for doctree::Module<'_> {
229229        let  attrs = self . attrs . clean ( cx) ; 
230230
231231        let  mut  items:  Vec < Item >  = vec ! [ ] ; 
232-         items. extend ( self . extern_crates . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ; 
233232        items. extend ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ; 
234233        items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ; 
235234        items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ; 
@@ -2004,6 +2003,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
20042003                    is_auto :  is_auto. clean ( cx) , 
20052004                } ) 
20062005            } 
2006+             ItemKind :: ExternCrate ( orig_name)  => { 
2007+                 return  clean_extern_crate ( item,  name,  orig_name,  cx) ; 
2008+             } 
20072009            _ => unreachable ! ( "not yet converted" ) , 
20082010        } ; 
20092011
@@ -2081,45 +2083,54 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
20812083    ret
20822084} 
20832085
2084- impl  Clean < Vec < Item > >  for  doctree:: ExternCrate < ' _ >  { 
2085-     fn  clean ( & self ,  cx :  & DocContext < ' _ > )  -> Vec < Item >  { 
2086-         let  please_inline = self . vis . node . is_pub ( ) 
2087-             && self . attrs . iter ( ) . any ( |a| { 
2088-                 a. has_name ( sym:: doc) 
2089-                     && match  a. meta_item_list ( )  { 
2090-                         Some ( l)  => attr:: list_contains_name ( & l,  sym:: inline) , 
2091-                         None  => false , 
2092-                     } 
2093-             } ) ; 
2086+ fn  clean_extern_crate ( 
2087+     krate :  & hir:: Item < ' _ > , 
2088+     name :  Symbol , 
2089+     orig_name :  Option < Symbol > , 
2090+     cx :  & DocContext < ' _ > , 
2091+ )  -> Vec < Item >  { 
2092+     // this is the ID of the `extern crate` statement 
2093+     let  def_id = cx. tcx . hir ( ) . local_def_id ( krate. hir_id ) ; 
2094+     let  cnum = cx. tcx . extern_mod_stmt_cnum ( def_id) . unwrap_or ( LOCAL_CRATE ) ; 
2095+     // this is the ID of the crate itself 
2096+     let  crate_def_id = DefId  {  krate :  cnum,  index :  CRATE_DEF_INDEX  } ; 
2097+     let  please_inline = krate. vis . node . is_pub ( ) 
2098+         && krate. attrs . iter ( ) . any ( |a| { 
2099+             a. has_name ( sym:: doc) 
2100+                 && match  a. meta_item_list ( )  { 
2101+                     Some ( l)  => attr:: list_contains_name ( & l,  sym:: inline) , 
2102+                     None  => false , 
2103+                 } 
2104+         } ) ; 
20942105
2095-          if  please_inline { 
2096-              let  mut  visited = FxHashSet :: default ( ) ; 
2106+     if  please_inline { 
2107+         let  mut  visited = FxHashSet :: default ( ) ; 
20972108
2098-              let  res = Res :: Def ( DefKind :: Mod ,  DefId   {   krate :   self . cnum ,   index :   CRATE_DEF_INDEX   } ) ; 
2109+         let  res = Res :: Def ( DefKind :: Mod ,  crate_def_id ) ; 
20992110
2100-             if  let  Some ( items)  = inline:: try_inline ( 
2101-                 cx, 
2102-                 cx. tcx . parent_module ( self . hir_id ) . to_def_id ( ) , 
2103-                 res, 
2104-                 self . name , 
2105-                 Some ( self . attrs ) , 
2106-                 & mut  visited, 
2107-             )  { 
2108-                 return  items; 
2109-             } 
2111+         if  let  Some ( items)  = inline:: try_inline ( 
2112+             cx, 
2113+             cx. tcx . parent_module ( krate. hir_id ) . to_def_id ( ) , 
2114+             res, 
2115+             name, 
2116+             Some ( krate. attrs ) , 
2117+             & mut  visited, 
2118+         )  { 
2119+             return  items; 
21102120        } 
2111- 
2112-         vec ! [ Item  { 
2113-             name:  None , 
2114-             attrs:  self . attrs. clean( cx) , 
2115-             source:  self . span. clean( cx) , 
2116-             def_id:  DefId  {  krate:  self . cnum,  index:  CRATE_DEF_INDEX  } , 
2117-             visibility:  self . vis. clean( cx) , 
2118-             stability:  None , 
2119-             deprecation:  None , 
2120-             kind:  ExternCrateItem ( self . name. clean( cx) ,  self . path. clone( ) ) , 
2121-         } ] 
21222121    } 
2122+     let  path = orig_name. map ( |x| x. to_string ( ) ) ; 
2123+     // FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason 
2124+     vec ! [ Item  { 
2125+         name:  None , 
2126+         attrs:  krate. attrs. clean( cx) , 
2127+         source:  krate. span. clean( cx) , 
2128+         def_id:  crate_def_id, 
2129+         visibility:  krate. vis. clean( cx) , 
2130+         stability:  None , 
2131+         deprecation:  None , 
2132+         kind:  ExternCrateItem ( name. clean( cx) ,  path) , 
2133+     } ] 
21232134} 
21242135
21252136impl  Clean < Vec < Item > >  for  doctree:: Import < ' _ >  { 
0 commit comments