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