@@ -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 ( ) ) ;
@@ -2019,7 +2018,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
2019
2018
ItemKind :: Fn ( ref sig, ref generics, body_id) => {
2020
2019
clean_fn_or_proc_macro ( item, sig, generics, body_id, & mut name, cx)
2021
2020
}
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) => {
2023
2022
let items = item_ids
2024
2023
. iter ( )
2025
2024
. map ( |ti| cx. tcx . hir ( ) . trait_item ( ti. id ) . clean ( cx) )
@@ -2038,6 +2037,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
2038
2037
ItemKind :: ExternCrate ( orig_name) => {
2039
2038
return clean_extern_crate ( item, name, orig_name, cx) ;
2040
2039
}
2040
+ ItemKind :: Use ( path, kind) => {
2041
+ return clean_use_statement ( item, name, path, kind, cx) ;
2042
+ }
2041
2043
_ => unreachable ! ( "not yet converted" ) ,
2042
2044
} ;
2043
2045
@@ -2159,105 +2161,101 @@ fn clean_extern_crate(
2159
2161
} ]
2160
2162
}
2161
2163
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
+ }
2184
2191
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)
2199
2204
}
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 ,
2209
2206
}
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;
2210
2217
}
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 ;
2221
2227
}
2222
2228
}
2223
- if !denied {
2224
- let mut visited = FxHashSet :: default ( ) ;
2229
+ }
2230
+ if !denied {
2231
+ let mut visited = FxHashSet :: default ( ) ;
2225
2232
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 ) ) ,
2227
2245
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;
2248
2248
}
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
+ } ;
2251
2252
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
+ ) ]
2261
2259
}
2262
2260
2263
2261
impl Clean < Item > for ( & hir:: ForeignItem < ' _ > , Option < Symbol > ) {
0 commit comments