@@ -136,94 +136,90 @@ pub struct Crate {
136136 pub collapsed : bool ,
137137}
138138
139- impl Clean < Crate > for hir:: Crate {
140- // note that self here is ignored in favor of `cx.tcx.hir().krate()` since
141- // that gets around tying self's lifetime to the '_ in cx.
142- fn clean ( & self , cx : & DocContext < ' _ > ) -> Crate {
143- use crate :: visit_lib:: LibEmbargoVisitor ;
144-
145- let v = crate :: visit_ast:: RustdocVisitor :: new ( & cx) ;
146- let module = v. visit ( cx. tcx . hir ( ) . krate ( ) ) ;
147-
148- {
149- let mut r = cx. renderinfo . borrow_mut ( ) ;
150- r. deref_trait_did = cx. tcx . lang_items ( ) . deref_trait ( ) ;
151- r. deref_mut_trait_did = cx. tcx . lang_items ( ) . deref_mut_trait ( ) ;
152- r. owned_box_did = cx. tcx . lang_items ( ) . owned_box ( ) ;
153- }
154-
155- let mut externs = Vec :: new ( ) ;
156- for & cnum in cx. tcx . crates ( ) . iter ( ) {
157- externs. push ( ( cnum, cnum. clean ( cx) ) ) ;
158- // Analyze doc-reachability for extern items
159- LibEmbargoVisitor :: new ( cx) . visit_lib ( cnum) ;
160- }
161- externs. sort_by ( |& ( a, _) , & ( b, _) | a. cmp ( & b) ) ;
162-
163- // Clean the crate, translating the entire libsyntax AST to one that is
164- // understood by rustdoc.
165- let mut module = module. clean ( cx) ;
166- let mut masked_crates = FxHashSet :: default ( ) ;
167-
168- match module. inner {
169- ModuleItem ( ref module) => {
170- for it in & module. items {
171- // `compiler_builtins` should be masked too, but we can't apply
172- // `#[doc(masked)]` to the injected `extern crate` because it's unstable.
173- if it. is_extern_crate ( )
174- && ( it. attrs . has_doc_flag ( sym:: masked)
175- || cx. tcx . is_compiler_builtins ( it. def_id . krate ) )
176- {
177- masked_crates. insert ( it. def_id . krate ) ;
178- }
179- }
180- }
181- _ => unreachable ! ( ) ,
182- }
139+ pub fn krate ( cx : & mut DocContext < ' a > ) -> Crate {
140+ use crate :: visit_lib:: LibEmbargoVisitor ;
183141
184- let ExternalCrate { name, src, primitives, keywords, .. } = LOCAL_CRATE . clean ( cx) ;
185- {
186- let m = match module. inner {
187- ModuleItem ( ref mut m) => m,
188- _ => unreachable ! ( ) ,
189- } ;
190- m. items . extend ( primitives. iter ( ) . map ( |& ( def_id, prim, ref attrs) | {
191- Item {
192- source : Span :: empty ( ) ,
193- name : Some ( prim. to_url_str ( ) . to_string ( ) ) ,
194- attrs : attrs. clone ( ) ,
195- visibility : Some ( Public ) ,
196- stability : get_stability ( cx, def_id) ,
197- deprecation : get_deprecation ( cx, def_id) ,
198- def_id,
199- inner : PrimitiveItem ( prim) ,
200- }
201- } ) ) ;
202- m. items . extend ( keywords. into_iter ( ) . map ( |( def_id, kw, attrs) | {
203- Item {
204- source : Span :: empty ( ) ,
205- name : Some ( kw. clone ( ) ) ,
206- attrs : attrs,
207- visibility : Some ( Public ) ,
208- stability : get_stability ( cx, def_id) ,
209- deprecation : get_deprecation ( cx, def_id) ,
210- def_id,
211- inner : KeywordItem ( kw) ,
142+ let v = crate :: visit_ast:: RustdocVisitor :: new ( & cx) ;
143+ let module = v. visit ( cx. tcx . hir ( ) . krate ( ) ) ;
144+
145+ {
146+ let mut r = cx. renderinfo . borrow_mut ( ) ;
147+ r. deref_trait_did = cx. tcx . lang_items ( ) . deref_trait ( ) ;
148+ r. deref_mut_trait_did = cx. tcx . lang_items ( ) . deref_mut_trait ( ) ;
149+ r. owned_box_did = cx. tcx . lang_items ( ) . owned_box ( ) ;
150+ }
151+
152+ let mut externs = Vec :: new ( ) ;
153+ for & cnum in cx. tcx . crates ( ) . iter ( ) {
154+ externs. push ( ( cnum, cnum. clean ( cx) ) ) ;
155+ // Analyze doc-reachability for extern items
156+ LibEmbargoVisitor :: new ( cx) . visit_lib ( cnum) ;
157+ }
158+ externs. sort_by ( |& ( a, _) , & ( b, _) | a. cmp ( & b) ) ;
159+
160+ // Clean the crate, translating the entire libsyntax AST to one that is
161+ // understood by rustdoc.
162+ let mut module = module. clean ( cx) ;
163+ let mut masked_crates = FxHashSet :: default ( ) ;
164+
165+ match module. inner {
166+ ModuleItem ( ref module) => {
167+ for it in & module. items {
168+ // `compiler_builtins` should be masked too, but we can't apply
169+ // `#[doc(masked)]` to the injected `extern crate` because it's unstable.
170+ if it. is_extern_crate ( )
171+ && ( it. attrs . has_doc_flag ( sym:: masked)
172+ || cx. tcx . is_compiler_builtins ( it. def_id . krate ) )
173+ {
174+ masked_crates. insert ( it. def_id . krate ) ;
212175 }
213- } ) ) ;
176+ }
214177 }
178+ _ => unreachable ! ( ) ,
179+ }
215180
216- Crate {
217- name,
218- version : None ,
219- src,
220- module : Some ( module) ,
221- externs,
222- primitives,
223- external_traits : cx. external_traits . clone ( ) ,
224- masked_crates,
225- collapsed : false ,
226- }
181+ let ExternalCrate { name, src, primitives, keywords, .. } = LOCAL_CRATE . clean ( cx) ;
182+ {
183+ let m = match module. inner {
184+ ModuleItem ( ref mut m) => m,
185+ _ => unreachable ! ( ) ,
186+ } ;
187+ m. items . extend ( primitives. iter ( ) . map ( |& ( def_id, prim, ref attrs) | {
188+ Item {
189+ source : Span :: empty ( ) ,
190+ name : Some ( prim. to_url_str ( ) . to_string ( ) ) ,
191+ attrs : attrs. clone ( ) ,
192+ visibility : Some ( Public ) ,
193+ stability : get_stability ( cx, def_id) ,
194+ deprecation : get_deprecation ( cx, def_id) ,
195+ def_id,
196+ inner : PrimitiveItem ( prim) ,
197+ }
198+ } ) ) ;
199+ m. items . extend ( keywords. into_iter ( ) . map ( |( def_id, kw, attrs) | {
200+ Item {
201+ source : Span :: empty ( ) ,
202+ name : Some ( kw. clone ( ) ) ,
203+ attrs : attrs,
204+ visibility : Some ( Public ) ,
205+ stability : get_stability ( cx, def_id) ,
206+ deprecation : get_deprecation ( cx, def_id) ,
207+ def_id,
208+ inner : KeywordItem ( kw) ,
209+ }
210+ } ) ) ;
211+ }
212+
213+ Crate {
214+ name,
215+ version : None ,
216+ src,
217+ module : Some ( module) ,
218+ externs,
219+ primitives,
220+ external_traits : cx. external_traits . clone ( ) ,
221+ masked_crates,
222+ collapsed : false ,
227223 }
228224}
229225
0 commit comments