@@ -219,7 +219,6 @@ impl Clean<ExternalCrate> for CrateNum {
219219impl Clean < Item > for doctree:: Module < ' _ > {
220220 fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
221221 let mut items: Vec < Item > = vec ! [ ] ;
222- items. extend ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
223222 items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
224223 items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
225224 items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) . flatten ( ) ) ;
@@ -2019,7 +2018,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
20192018 ItemKind :: Fn ( ref sig, ref generics, body_id) => {
20202019 clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
20212020 }
2022- hir :: ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
2021+ ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
20232022 let items = item_ids
20242023 . iter ( )
20252024 . map ( |ti| cx. tcx . hir ( ) . trait_item ( ti. id ) . clean ( cx) )
@@ -2038,6 +2037,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
20382037 ItemKind :: ExternCrate ( orig_name) => {
20392038 return clean_extern_crate ( item, name, orig_name, cx) ;
20402039 }
2040+ ItemKind :: Use ( path, kind) => {
2041+ return clean_use_statement ( item, name, path, kind, cx) ;
2042+ }
20412043 _ => unreachable ! ( "not yet converted" ) ,
20422044 } ;
20432045
@@ -2159,105 +2161,101 @@ fn clean_extern_crate(
21592161 } ]
21602162}
21612163
2162- impl Clean < Vec < Item > > for doctree:: Import < ' _ > {
2163- fn clean ( & self , cx : & DocContext < ' _ > ) -> Vec < Item > {
2164- // We need this comparison because some imports (for std types for example)
2165- // are "inserted" as well but directly by the compiler and they should not be
2166- // taken into account.
2167- if self . span . ctxt ( ) . outer_expn_data ( ) . kind == ExpnKind :: AstPass ( AstPass :: StdImports ) {
2168- return Vec :: new ( ) ;
2169- }
2170-
2171- let ( doc_meta_item, please_inline) = self . attrs . lists ( sym:: doc) . get_word_attr ( sym:: inline) ;
2172- let pub_underscore = self . vis . node . is_pub ( ) && self . name == kw:: Underscore ;
2173-
2174- if pub_underscore && please_inline {
2175- rustc_errors:: struct_span_err!(
2176- cx. tcx. sess,
2177- doc_meta_item. unwrap( ) . span( ) ,
2178- E0780 ,
2179- "anonymous imports cannot be inlined"
2180- )
2181- . span_label ( self . span , "anonymous import" )
2182- . emit ( ) ;
2183- }
2164+ fn clean_use_statement (
2165+ import : & hir:: Item < ' _ > ,
2166+ name : Symbol ,
2167+ path : & hir:: Path < ' _ > ,
2168+ kind : hir:: UseKind ,
2169+ cx : & DocContext < ' _ > ,
2170+ ) -> Vec < Item > {
2171+ // We need this comparison because some imports (for std types for example)
2172+ // are "inserted" as well but directly by the compiler and they should not be
2173+ // taken into account.
2174+ if import. span . ctxt ( ) . outer_expn_data ( ) . kind == ExpnKind :: AstPass ( AstPass :: StdImports ) {
2175+ return Vec :: new ( ) ;
2176+ }
2177+
2178+ let ( doc_meta_item, please_inline) = import. attrs . lists ( sym:: doc) . get_word_attr ( sym:: inline) ;
2179+ let pub_underscore = import. vis . node . is_pub ( ) && name == kw:: Underscore ;
2180+
2181+ if pub_underscore && please_inline {
2182+ rustc_errors:: struct_span_err!(
2183+ cx. tcx. sess,
2184+ doc_meta_item. unwrap( ) . span( ) ,
2185+ E0780 ,
2186+ "anonymous imports cannot be inlined"
2187+ )
2188+ . span_label ( import. span , "anonymous import" )
2189+ . emit ( ) ;
2190+ }
21842191
2185- // We consider inlining the documentation of `pub use` statements, but we
2186- // forcefully don't inline if this is not public or if the
2187- // #[doc(no_inline)] attribute is present.
2188- // Don't inline doc(hidden) imports so they can be stripped at a later stage.
2189- let mut denied = !self . vis . node . is_pub ( )
2190- || pub_underscore
2191- || self . attrs . iter ( ) . any ( |a| {
2192- a. has_name ( sym:: doc)
2193- && match a. meta_item_list ( ) {
2194- Some ( l) => {
2195- attr:: list_contains_name ( & l, sym:: no_inline)
2196- || attr:: list_contains_name ( & l, sym:: hidden)
2197- }
2198- None => false ,
2192+ // We consider inlining the documentation of `pub use` statements, but we
2193+ // forcefully don't inline if this is not public or if the
2194+ // #[doc(no_inline)] attribute is present.
2195+ // Don't inline doc(hidden) imports so they can be stripped at a later stage.
2196+ let mut denied = !import. vis . node . is_pub ( )
2197+ || pub_underscore
2198+ || import. attrs . iter ( ) . any ( |a| {
2199+ a. has_name ( sym:: doc)
2200+ && match a. meta_item_list ( ) {
2201+ Some ( l) => {
2202+ attr:: list_contains_name ( & l, sym:: no_inline)
2203+ || attr:: list_contains_name ( & l, sym:: hidden)
21992204 }
2200- } ) ;
2201- // Also check whether imports were asked to be inlined, in case we're trying to re-export a
2202- // crate in Rust 2018+
2203- let path = self . path . clean ( cx) ;
2204- let inner = if self . glob {
2205- if !denied {
2206- let mut visited = FxHashSet :: default ( ) ;
2207- if let Some ( items) = inline:: try_inline_glob ( cx, path. res , & mut visited) {
2208- return items;
2205+ None => false ,
22092206 }
2207+ } ) ;
2208+
2209+ // Also check whether imports were asked to be inlined, in case we're trying to re-export a
2210+ // crate in Rust 2018+
2211+ let path = path. clean ( cx) ;
2212+ let inner = if kind == hir:: UseKind :: Glob {
2213+ if !denied {
2214+ let mut visited = FxHashSet :: default ( ) ;
2215+ if let Some ( items) = inline:: try_inline_glob ( cx, path. res , & mut visited) {
2216+ return items;
22102217 }
2211- Import :: new_glob ( resolve_use_source ( cx, path) , true )
2212- } else {
2213- let name = self . name ;
2214- if !please_inline {
2215- if let Res :: Def ( DefKind :: Mod , did) = path. res {
2216- if !did. is_local ( ) && did. index == CRATE_DEF_INDEX {
2217- // if we're `pub use`ing an extern crate root, don't inline it unless we
2218- // were specifically asked for it
2219- denied = true ;
2220- }
2218+ }
2219+ Import :: new_glob ( resolve_use_source ( cx, path) , true )
2220+ } else {
2221+ if !please_inline {
2222+ if let Res :: Def ( DefKind :: Mod , did) = path. res {
2223+ if !did. is_local ( ) && did. index == CRATE_DEF_INDEX {
2224+ // if we're `pub use`ing an extern crate root, don't inline it unless we
2225+ // were specifically asked for it
2226+ denied = true ;
22212227 }
22222228 }
2223- if !denied {
2224- let mut visited = FxHashSet :: default ( ) ;
2229+ }
2230+ if !denied {
2231+ let mut visited = FxHashSet :: default ( ) ;
22252232
2226- if let Some ( mut items) = inline:: try_inline (
2233+ if let Some ( mut items) = inline:: try_inline (
2234+ cx,
2235+ cx. tcx . parent_module ( import. hir_id ) . to_def_id ( ) ,
2236+ path. res ,
2237+ name,
2238+ Some ( import. attrs ) ,
2239+ & mut visited,
2240+ ) {
2241+ items. push ( Item :: from_def_id_and_parts (
2242+ cx. tcx . hir ( ) . local_def_id ( import. hir_id ) . to_def_id ( ) ,
2243+ None ,
2244+ ImportItem ( Import :: new_simple ( name, resolve_use_source ( cx, path) , false ) ) ,
22272245 cx,
2228- cx. tcx . parent_module ( self . id ) . to_def_id ( ) ,
2229- path. res ,
2230- name,
2231- Some ( self . attrs ) ,
2232- & mut visited,
2233- ) {
2234- items. push ( Item {
2235- name : None ,
2236- attrs : box self . attrs . clean ( cx) ,
2237- source : self . span . clean ( cx) ,
2238- def_id : cx. tcx . hir ( ) . local_def_id ( self . id ) . to_def_id ( ) ,
2239- visibility : self . vis . clean ( cx) ,
2240- kind : box ImportItem ( Import :: new_simple (
2241- self . name ,
2242- resolve_use_source ( cx, path) ,
2243- false ,
2244- ) ) ,
2245- } ) ;
2246- return items;
2247- }
2246+ ) ) ;
2247+ return items;
22482248 }
2249- Import :: new_simple ( name, resolve_use_source ( cx, path) , true )
2250- } ;
2249+ }
2250+ Import :: new_simple ( name, resolve_use_source ( cx, path) , true )
2251+ } ;
22512252
2252- vec ! [ Item {
2253- name: None ,
2254- attrs: box self . attrs. clean( cx) ,
2255- source: self . span. clean( cx) ,
2256- def_id: cx. tcx. hir( ) . local_def_id( self . id) . to_def_id( ) ,
2257- visibility: self . vis. clean( cx) ,
2258- kind: box ImportItem ( inner) ,
2259- } ]
2260- }
2253+ vec ! [ Item :: from_def_id_and_parts(
2254+ cx. tcx. hir( ) . local_def_id( import. hir_id) . to_def_id( ) ,
2255+ None ,
2256+ ImportItem ( inner) ,
2257+ cx,
2258+ ) ]
22612259}
22622260
22632261impl Clean < Item > for ( & hir:: ForeignItem < ' _ > , Option < Symbol > ) {
0 commit comments