@@ -48,75 +48,68 @@ pub(crate) trait Clean<'tcx, T> {
48
48
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> T ;
49
49
}
50
50
51
- impl < ' tcx > Clean < ' tcx , Item > for DocModule < ' tcx > {
52
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Item {
53
- let mut items: Vec < Item > = vec ! [ ] ;
54
- let mut inserted = FxHashSet :: default ( ) ;
55
- items. extend ( self . foreigns . iter ( ) . map ( |( item, renamed) | {
56
- let item = clean_maybe_renamed_foreign_item ( cx, item, * renamed) ;
51
+ pub ( crate ) fn clean_doc_module < ' tcx > ( doc : & DocModule < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Item {
52
+ let mut items: Vec < Item > = vec ! [ ] ;
53
+ let mut inserted = FxHashSet :: default ( ) ;
54
+ items. extend ( doc. foreigns . iter ( ) . map ( |( item, renamed) | {
55
+ let item = clean_maybe_renamed_foreign_item ( cx, item, * renamed) ;
56
+ if let Some ( name) = item. name {
57
+ inserted. insert ( ( item. type_ ( ) , name) ) ;
58
+ }
59
+ item
60
+ } ) ) ;
61
+ items. extend ( doc. mods . iter ( ) . map ( |x| {
62
+ inserted. insert ( ( ItemType :: Module , x. name ) ) ;
63
+ clean_doc_module ( x, cx)
64
+ } ) ) ;
65
+
66
+ // Split up imports from all other items.
67
+ //
68
+ // This covers the case where somebody does an import which should pull in an item,
69
+ // but there's already an item with the same namespace and same name. Rust gives
70
+ // priority to the not-imported one, so we should, too.
71
+ items. extend ( doc. items . iter ( ) . flat_map ( |( item, renamed) | {
72
+ // First, lower everything other than imports.
73
+ if matches ! ( item. kind, hir:: ItemKind :: Use ( _, hir:: UseKind :: Glob ) ) {
74
+ return Vec :: new ( ) ;
75
+ }
76
+ let v = clean_maybe_renamed_item ( cx, item, * renamed) ;
77
+ for item in & v {
57
78
if let Some ( name) = item. name {
58
79
inserted. insert ( ( item. type_ ( ) , name) ) ;
59
80
}
60
- item
61
- } ) ) ;
62
- items. extend ( self . mods . iter ( ) . map ( |x| {
63
- inserted. insert ( ( ItemType :: Module , x. name ) ) ;
64
- x. clean ( cx)
65
- } ) ) ;
66
-
67
- // Split up imports from all other items.
68
- //
69
- // This covers the case where somebody does an import which should pull in an item,
70
- // but there's already an item with the same namespace and same name. Rust gives
71
- // priority to the not-imported one, so we should, too.
72
- items. extend ( self . items . iter ( ) . flat_map ( |( item, renamed) | {
73
- // First, lower everything other than imports.
74
- if matches ! ( item. kind, hir:: ItemKind :: Use ( _, hir:: UseKind :: Glob ) ) {
75
- return Vec :: new ( ) ;
76
- }
77
- let v = clean_maybe_renamed_item ( cx, item, * renamed) ;
78
- for item in & v {
79
- if let Some ( name) = item. name {
80
- inserted. insert ( ( item. type_ ( ) , name) ) ;
81
- }
82
- }
83
- v
84
- } ) ) ;
85
- items. extend ( self . items . iter ( ) . flat_map ( |( item, renamed) | {
86
- // Now we actually lower the imports, skipping everything else.
87
- if let hir:: ItemKind :: Use ( path, hir:: UseKind :: Glob ) = item. kind {
88
- let name = renamed. unwrap_or_else ( || cx. tcx . hir ( ) . name ( item. hir_id ( ) ) ) ;
89
- clean_use_statement ( item, name, path, hir:: UseKind :: Glob , cx, & mut inserted)
90
- } else {
91
- // skip everything else
92
- Vec :: new ( )
93
- }
94
- } ) ) ;
95
-
96
- // determine if we should display the inner contents or
97
- // the outer `mod` item for the source code.
98
-
99
- let span = Span :: new ( {
100
- let where_outer = self . where_outer ( cx. tcx ) ;
101
- let sm = cx. sess ( ) . source_map ( ) ;
102
- let outer = sm. lookup_char_pos ( where_outer. lo ( ) ) ;
103
- let inner = sm. lookup_char_pos ( self . where_inner . lo ( ) ) ;
104
- if outer. file . start_pos == inner. file . start_pos {
105
- // mod foo { ... }
106
- where_outer
107
- } else {
108
- // mod foo; (and a separate SourceFile for the contents)
109
- self . where_inner
110
- }
111
- } ) ;
81
+ }
82
+ v
83
+ } ) ) ;
84
+ items. extend ( doc. items . iter ( ) . flat_map ( |( item, renamed) | {
85
+ // Now we actually lower the imports, skipping everything else.
86
+ if let hir:: ItemKind :: Use ( path, hir:: UseKind :: Glob ) = item. kind {
87
+ let name = renamed. unwrap_or_else ( || cx. tcx . hir ( ) . name ( item. hir_id ( ) ) ) ;
88
+ clean_use_statement ( item, name, path, hir:: UseKind :: Glob , cx, & mut inserted)
89
+ } else {
90
+ // skip everything else
91
+ Vec :: new ( )
92
+ }
93
+ } ) ) ;
94
+
95
+ // determine if we should display the inner contents or
96
+ // the outer `mod` item for the source code.
97
+
98
+ let span = Span :: new ( {
99
+ let where_outer = doc. where_outer ( cx. tcx ) ;
100
+ let sm = cx. sess ( ) . source_map ( ) ;
101
+ let outer = sm. lookup_char_pos ( where_outer. lo ( ) ) ;
102
+ let inner = sm. lookup_char_pos ( doc. where_inner . lo ( ) ) ;
103
+ if outer. file . start_pos == inner. file . start_pos {
104
+ // mod foo { ... }
105
+ where_outer
106
+ } else {
107
+ // mod foo; (and a separate SourceFile for the contents)
108
+ doc. where_inner
109
+ }
110
+ } ) ;
112
111
113
- Item :: from_hir_id_and_parts (
114
- self . id ,
115
- Some ( self . name ) ,
116
- ModuleItem ( Module { items, span } ) ,
117
- cx,
118
- )
119
- }
112
+ Item :: from_hir_id_and_parts ( doc. id , Some ( doc. name ) , ModuleItem ( Module { items, span } ) , cx)
120
113
}
121
114
122
115
fn clean_generic_bound < ' tcx > (
0 commit comments