@@ -219,7 +219,6 @@ impl Clean<ExternalCrate> for CrateNum {
219
219
impl Clean < Item > for doctree:: Module < ' _ > {
220
220
fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
221
221
let mut items: Vec < Item > = vec ! [ ] ;
222
- items. extend ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) ) ) ;
223
222
items. extend ( self . foreigns . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
224
223
items. extend ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) ) ;
225
224
items. extend ( self . items . iter ( ) . map ( |x| x. clean ( cx) ) . flatten ( ) ) ;
@@ -2032,7 +2031,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
2032
2031
ItemKind :: Fn ( ref sig, ref generics, body_id) => {
2033
2032
clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2034
2033
}
2035
- hir :: ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
2034
+ ItemKind :: Trait ( is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
2036
2035
let items = item_ids
2037
2036
. iter ( )
2038
2037
. map ( |ti| cx. tcx . hir ( ) . trait_item ( ti. id ) . clean ( cx) )
@@ -2051,6 +2050,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
2051
2050
ItemKind :: ExternCrate ( orig_name) => {
2052
2051
return clean_extern_crate ( item, name, orig_name, cx) ;
2053
2052
}
2053
+ ItemKind :: Use ( path, kind) => {
2054
+ return clean_use_statement ( item, name, path, kind, cx) ;
2055
+ }
2054
2056
_ => unreachable ! ( "not yet converted" ) ,
2055
2057
} ;
2056
2058
@@ -2172,105 +2174,97 @@ fn clean_extern_crate(
2172
2174
} ]
2173
2175
}
2174
2176
2175
- impl Clean < Vec < Item > > for doctree:: Import < ' _ > {
2176
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Vec < Item > {
2177
- // We need this comparison because some imports (for std types for example)
2178
- // are "inserted" as well but directly by the compiler and they should not be
2179
- // taken into account.
2180
- if self . span . ctxt ( ) . outer_expn_data ( ) . kind == ExpnKind :: AstPass ( AstPass :: StdImports ) {
2181
- return Vec :: new ( ) ;
2182
- }
2183
-
2184
- let ( doc_meta_item, please_inline) = self . attrs . lists ( sym:: doc) . get_word_attr ( sym:: inline) ;
2185
- let pub_underscore = self . vis . node . is_pub ( ) && self . name == kw:: Underscore ;
2186
-
2187
- if pub_underscore && please_inline {
2188
- rustc_errors:: struct_span_err!(
2189
- cx. tcx. sess,
2190
- doc_meta_item. unwrap( ) . span( ) ,
2191
- E0780 ,
2192
- "anonymous imports cannot be inlined"
2193
- )
2194
- . span_label ( self . span , "anonymous import" )
2195
- . emit ( ) ;
2196
- }
2177
+ fn clean_use_statement (
2178
+ import : & hir:: Item < ' _ > ,
2179
+ name : Symbol ,
2180
+ path : & hir:: Path < ' _ > ,
2181
+ kind : hir:: UseKind ,
2182
+ cx : & DocContext < ' _ > ,
2183
+ ) -> Vec < Item > {
2184
+ // We need this comparison because some imports (for std types for example)
2185
+ // are "inserted" as well but directly by the compiler and they should not be
2186
+ // taken into account.
2187
+ if import. span . ctxt ( ) . outer_expn_data ( ) . kind == ExpnKind :: AstPass ( AstPass :: StdImports ) {
2188
+ return Vec :: new ( ) ;
2189
+ }
2190
+
2191
+ let ( doc_meta_item, please_inline) = import. attrs . lists ( sym:: doc) . get_word_attr ( sym:: inline) ;
2192
+ let pub_underscore = import. vis . node . is_pub ( ) && name == kw:: Underscore ;
2193
+
2194
+ if pub_underscore && please_inline {
2195
+ rustc_errors:: struct_span_err!(
2196
+ cx. tcx. sess,
2197
+ doc_meta_item. unwrap( ) . span( ) ,
2198
+ E0780 ,
2199
+ "anonymous imports cannot be inlined"
2200
+ )
2201
+ . span_label ( import. span , "anonymous import" )
2202
+ . emit ( ) ;
2203
+ }
2197
2204
2198
- // We consider inlining the documentation of `pub use` statements, but we
2199
- // forcefully don't inline if this is not public or if the
2200
- // #[doc(no_inline)] attribute is present.
2201
- // Don't inline doc(hidden) imports so they can be stripped at a later stage.
2202
- let mut denied = !self . vis . node . is_pub ( )
2203
- || pub_underscore
2204
- || self . attrs . iter ( ) . any ( |a| {
2205
- a. has_name ( sym:: doc)
2206
- && match a. meta_item_list ( ) {
2207
- Some ( l) => {
2208
- attr:: list_contains_name ( & l, sym:: no_inline)
2209
- || attr:: list_contains_name ( & l, sym:: hidden)
2210
- }
2211
- None => false ,
2205
+ // We consider inlining the documentation of `pub use` statements, but we
2206
+ // forcefully don't inline if this is not public or if the
2207
+ // #[doc(no_inline)] attribute is present.
2208
+ // Don't inline doc(hidden) imports so they can be stripped at a later stage.
2209
+ let mut denied = !import. vis . node . is_pub ( )
2210
+ || pub_underscore
2211
+ || import. attrs . iter ( ) . any ( |a| {
2212
+ a. has_name ( sym:: doc)
2213
+ && match a. meta_item_list ( ) {
2214
+ Some ( l) => {
2215
+ attr:: list_contains_name ( & l, sym:: no_inline)
2216
+ || attr:: list_contains_name ( & l, sym:: hidden)
2212
2217
}
2213
- } ) ;
2214
- // Also check whether imports were asked to be inlined, in case we're trying to re-export a
2215
- // crate in Rust 2018+
2216
- let path = self . path . clean ( cx) ;
2217
- let inner = if self . glob {
2218
- if !denied {
2219
- let mut visited = FxHashSet :: default ( ) ;
2220
- if let Some ( items) = inline:: try_inline_glob ( cx, path. res , & mut visited) {
2221
- return items;
2218
+ None => false ,
2222
2219
}
2220
+ } ) ;
2221
+
2222
+ // Also check whether imports were asked to be inlined, in case we're trying to re-export a
2223
+ // crate in Rust 2018+
2224
+ let def_id = cx. tcx . hir ( ) . local_def_id ( import. hir_id ) . to_def_id ( ) ;
2225
+ let path = path. clean ( cx) ;
2226
+ let inner = if kind == hir:: UseKind :: Glob {
2227
+ if !denied {
2228
+ let mut visited = FxHashSet :: default ( ) ;
2229
+ if let Some ( items) = inline:: try_inline_glob ( cx, path. res , & mut visited) {
2230
+ return items;
2223
2231
}
2224
- Import :: new_glob ( resolve_use_source ( cx, path) , true )
2225
- } else {
2226
- let name = self . name ;
2227
- if !please_inline {
2228
- if let Res :: Def ( DefKind :: Mod , did) = path. res {
2229
- if !did. is_local ( ) && did. index == CRATE_DEF_INDEX {
2230
- // if we're `pub use`ing an extern crate root, don't inline it unless we
2231
- // were specifically asked for it
2232
- denied = true ;
2233
- }
2232
+ }
2233
+ Import :: new_glob ( resolve_use_source ( cx, path) , true )
2234
+ } else {
2235
+ if !please_inline {
2236
+ if let Res :: Def ( DefKind :: Mod , did) = path. res {
2237
+ if !did. is_local ( ) && did. index == CRATE_DEF_INDEX {
2238
+ // if we're `pub use`ing an extern crate root, don't inline it unless we
2239
+ // were specifically asked for it
2240
+ denied = true ;
2234
2241
}
2235
2242
}
2236
- if !denied {
2237
- let mut visited = FxHashSet :: default ( ) ;
2243
+ }
2244
+ if !denied {
2245
+ let mut visited = FxHashSet :: default ( ) ;
2238
2246
2239
- if let Some ( mut items) = inline:: try_inline (
2247
+ if let Some ( mut items) = inline:: try_inline (
2248
+ cx,
2249
+ cx. tcx . parent_module ( import. hir_id ) . to_def_id ( ) ,
2250
+ path. res ,
2251
+ name,
2252
+ Some ( import. attrs ) ,
2253
+ & mut visited,
2254
+ ) {
2255
+ items. push ( Item :: from_def_id_and_parts (
2256
+ def_id,
2257
+ None ,
2258
+ ImportItem ( Import :: new_simple ( name, resolve_use_source ( cx, path) , false ) ) ,
2240
2259
cx,
2241
- cx. tcx . parent_module ( self . id ) . to_def_id ( ) ,
2242
- path. res ,
2243
- name,
2244
- Some ( self . attrs ) ,
2245
- & mut visited,
2246
- ) {
2247
- items. push ( Item {
2248
- name : None ,
2249
- attrs : box self . attrs . clean ( cx) ,
2250
- source : self . span . clean ( cx) ,
2251
- def_id : cx. tcx . hir ( ) . local_def_id ( self . id ) . to_def_id ( ) ,
2252
- visibility : self . vis . clean ( cx) ,
2253
- kind : box ImportItem ( Import :: new_simple (
2254
- self . name ,
2255
- resolve_use_source ( cx, path) ,
2256
- false ,
2257
- ) ) ,
2258
- } ) ;
2259
- return items;
2260
- }
2260
+ ) ) ;
2261
+ return items;
2261
2262
}
2262
- Import :: new_simple ( name, resolve_use_source ( cx, path) , true )
2263
- } ;
2263
+ }
2264
+ Import :: new_simple ( name, resolve_use_source ( cx, path) , true )
2265
+ } ;
2264
2266
2265
- vec ! [ Item {
2266
- name: None ,
2267
- attrs: box self . attrs. clean( cx) ,
2268
- source: self . span. clean( cx) ,
2269
- def_id: cx. tcx. hir( ) . local_def_id( self . id) . to_def_id( ) ,
2270
- visibility: self . vis. clean( cx) ,
2271
- kind: box ImportItem ( inner) ,
2272
- } ]
2273
- }
2267
+ vec ! [ Item :: from_def_id_and_parts( def_id, None , ImportItem ( inner) , cx) ]
2274
2268
}
2275
2269
2276
2270
impl Clean < Item > for ( & hir:: ForeignItem < ' _ > , Option < Symbol > ) {
0 commit comments