@@ -7,7 +7,7 @@ use crate::config::{RenderInfo, RenderOptions};
77use  crate :: error:: Error ; 
88use  crate :: formats:: cache:: { Cache ,  CACHE_KEY } ; 
99
10- /// Allows for different backends to rustdoc to be used with the `Renderer::run ()` function. Each 
10+ /// Allows for different backends to rustdoc to be used with the `run_format ()` function. Each 
1111/// backend renderer has hooks for initialization, documenting an item, entering and exiting a 
1212/// module, and cleanup/finalizing output. 
1313pub  trait  FormatRenderer :  Clone  { 
@@ -42,75 +42,65 @@ pub trait FormatRenderer: Clone {
4242     fn  after_run ( & mut  self ,  diag :  & rustc_errors:: Handler )  -> Result < ( ) ,  Error > ; 
4343} 
4444
45- #[ derive( Clone ) ]  
46- pub  struct  Renderer ; 
47- 
48- impl  Renderer  { 
49-     pub  fn  new ( )  -> Renderer  { 
50-         Renderer 
51-     } 
45+ /// Main method for rendering a crate. 
46+ pub  fn  run_format < T :  FormatRenderer > ( 
47+     krate :  clean:: Crate , 
48+     options :  RenderOptions , 
49+     render_info :  RenderInfo , 
50+     diag :  & rustc_errors:: Handler , 
51+     edition :  Edition , 
52+ )  -> Result < ( ) ,  Error >  { 
53+     let  ( krate,  mut  cache)  = Cache :: from_krate ( 
54+         render_info. clone ( ) , 
55+         options. document_private , 
56+         & options. extern_html_root_urls , 
57+         & options. output , 
58+         krate, 
59+     ) ; 
60+ 
61+     let  ( mut  format_renderer,  mut  krate)  =
62+         T :: init ( krate,  options,  render_info,  edition,  & mut  cache) ?; 
63+ 
64+     let  cache = Arc :: new ( cache) ; 
65+     // Freeze the cache now that the index has been built. Put an Arc into TLS for future 
66+     // parallelization opportunities 
67+     CACHE_KEY . with ( |v| * v. borrow_mut ( )  = cache. clone ( ) ) ; 
68+ 
69+     let  mut  item = match  krate. module . take ( )  { 
70+         Some ( i)  => i, 
71+         None  => return  Ok ( ( ) ) , 
72+     } ; 
73+ 
74+     item. name  = Some ( krate. name . clone ( ) ) ; 
75+ 
76+     // Render the crate documentation 
77+     let  mut  work = vec ! [ ( format_renderer. clone( ) ,  item) ] ; 
78+ 
79+     while  let  Some ( ( mut  cx,  item) )  = work. pop ( )  { 
80+         if  item. is_mod ( )  { 
81+             // modules are special because they add a namespace. We also need to 
82+             // recurse into the items of the module as well. 
83+             let  name = item. name . as_ref ( ) . unwrap ( ) . to_string ( ) ; 
84+             if  name. is_empty ( )  { 
85+                 panic ! ( "Unexpected module with empty name" ) ; 
86+             } 
5287
53-     /// Main method for rendering a crate. 
54-      pub  fn  run < T :  FormatRenderer  + Clone > ( 
55-         self , 
56-         krate :  clean:: Crate , 
57-         options :  RenderOptions , 
58-         render_info :  RenderInfo , 
59-         diag :  & rustc_errors:: Handler , 
60-         edition :  Edition , 
61-     )  -> Result < ( ) ,  Error >  { 
62-         let  ( krate,  mut  cache)  = Cache :: from_krate ( 
63-             render_info. clone ( ) , 
64-             options. document_private , 
65-             & options. extern_html_root_urls , 
66-             & options. output , 
67-             krate, 
68-         ) ; 
69- 
70-         let  ( mut  format_renderer,  mut  krate)  =
71-             T :: init ( krate,  options,  render_info,  edition,  & mut  cache) ?; 
72- 
73-         let  cache = Arc :: new ( cache) ; 
74-         // Freeze the cache now that the index has been built. Put an Arc into TLS for future 
75-         // parallelization opportunities 
76-         CACHE_KEY . with ( |v| * v. borrow_mut ( )  = cache. clone ( ) ) ; 
77- 
78-         let  mut  item = match  krate. module . take ( )  { 
79-             Some ( i)  => i, 
80-             None  => return  Ok ( ( ) ) , 
81-         } ; 
82- 
83-         item. name  = Some ( krate. name . clone ( ) ) ; 
84- 
85-         // Render the crate documentation 
86-         let  mut  work = vec ! [ ( format_renderer. clone( ) ,  item) ] ; 
87- 
88-         while  let  Some ( ( mut  cx,  item) )  = work. pop ( )  { 
89-             if  item. is_mod ( )  { 
90-                 // modules are special because they add a namespace. We also need to 
91-                 // recurse into the items of the module as well. 
92-                 let  name = item. name . as_ref ( ) . unwrap ( ) . to_string ( ) ; 
93-                 if  name. is_empty ( )  { 
94-                     panic ! ( "Unexpected module with empty name" ) ; 
95-                 } 
96- 
97-                 cx. mod_item_in ( & item,  & name,  & cache) ?; 
98-                 let  module = match  item. inner  { 
99-                     clean:: StrippedItem ( box clean:: ModuleItem ( m) )  | clean:: ModuleItem ( m)  => m, 
100-                     _ => unreachable ! ( ) , 
101-                 } ; 
102-                 for  it in  module. items  { 
103-                     debug ! ( "Adding {:?} to worklist" ,  it. name) ; 
104-                     work. push ( ( cx. clone ( ) ,  it) ) ; 
105-                 } 
106- 
107-                 cx. mod_item_out ( & name) ?; 
108-             }  else  if  item. name . is_some ( )  { 
109-                 cx. item ( item,  & cache) ?; 
88+             cx. mod_item_in ( & item,  & name,  & cache) ?; 
89+             let  module = match  item. inner  { 
90+                 clean:: StrippedItem ( box clean:: ModuleItem ( m) )  | clean:: ModuleItem ( m)  => m, 
91+                 _ => unreachable ! ( ) , 
92+             } ; 
93+             for  it in  module. items  { 
94+                 debug ! ( "Adding {:?} to worklist" ,  it. name) ; 
95+                 work. push ( ( cx. clone ( ) ,  it) ) ; 
11096            } 
111-         } 
11297
113-         format_renderer. after_krate ( & krate,  & cache) ?; 
114-         format_renderer. after_run ( diag) 
98+             cx. mod_item_out ( & name) ?; 
99+         }  else  if  item. name . is_some ( )  { 
100+             cx. item ( item,  & cache) ?; 
101+         } 
115102    } 
103+ 
104+     format_renderer. after_krate ( & krate,  & cache) ?; 
105+     format_renderer. after_run ( diag) 
116106} 
0 commit comments