@@ -1257,7 +1257,6 @@ impl Context {
12571257
12581258 info ! ( "Recursing into {}" , self . dst. display( ) ) ;
12591259
1260- mkdir ( & self . dst ) . unwrap ( ) ;
12611260 let ret = f ( self ) ;
12621261
12631262 info ! ( "Recursed; leaving {}" , self . dst. display( ) ) ;
@@ -1301,7 +1300,7 @@ impl Context {
13011300 fn item < F > ( & mut self , item : clean:: Item , mut f : F ) -> Result < ( ) , Error > where
13021301 F : FnMut ( & mut Context , clean:: Item ) ,
13031302 {
1304- fn render ( w : File , cx : & Context , it : & clean:: Item ,
1303+ fn render ( writer : & mut io :: Write , cx : & Context , it : & clean:: Item ,
13051304 pushname : bool ) -> io:: Result < ( ) > {
13061305 // A little unfortunate that this is done like this, but it sure
13071306 // does make formatting *a lot* nicer.
@@ -1336,12 +1335,8 @@ impl Context {
13361335
13371336 reset_ids ( true ) ;
13381337
1339- // We have a huge number of calls to write, so try to alleviate some
1340- // of the pain by using a buffered writer instead of invoking the
1341- // write syscall all the time.
1342- let mut writer = BufWriter :: new ( w) ;
13431338 if !cx. render_redirect_pages {
1344- layout:: render ( & mut writer, & cx. shared . layout , & page,
1339+ layout:: render ( writer, & cx. shared . layout , & page,
13451340 & Sidebar { cx : cx, item : it } ,
13461341 & Item { cx : cx, item : it } ,
13471342 cx. shared . css_file_extension . is_some ( ) ) ?;
@@ -1354,10 +1349,10 @@ impl Context {
13541349 url. push_str ( "/" ) ;
13551350 }
13561351 url. push_str ( & item_path ( it) ) ;
1357- layout:: redirect ( & mut writer, & url) ?;
1352+ layout:: redirect ( writer, & url) ?;
13581353 }
13591354 }
1360- writer . flush ( )
1355+ Ok ( ( ) )
13611356 }
13621357
13631358 // Stripped modules survive the rustdoc passes (i.e. `strip-private`)
@@ -1378,9 +1373,16 @@ impl Context {
13781373 let mut item = Some ( item) ;
13791374 self . recurse ( name, |this| {
13801375 let item = item. take ( ) . unwrap ( ) ;
1381- let joint_dst = this. dst . join ( "index.html" ) ;
1382- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1383- try_err ! ( render( dst, this, & item, false ) , & joint_dst) ;
1376+
1377+ let mut buf = Vec :: new ( ) ;
1378+ render ( & mut buf, this, & item, false ) . unwrap ( ) ;
1379+ // buf will be empty if the module is stripped and there is no redirect for it
1380+ if !buf. is_empty ( ) {
1381+ let joint_dst = this. dst . join ( "index.html" ) ;
1382+ try_err ! ( fs:: create_dir_all( & this. dst) , & this. dst) ;
1383+ let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1384+ try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1385+ }
13841386
13851387 let m = match item. inner {
13861388 clean:: StrippedItem ( box clean:: ModuleItem ( m) ) |
@@ -1389,7 +1391,7 @@ impl Context {
13891391 } ;
13901392
13911393 // render sidebar-items.js used throughout this module
1392- {
1394+ if !this . render_redirect_pages {
13931395 let items = this. build_sidebar_items ( & m) ;
13941396 let js_dst = this. dst . join ( "sidebar-items.js" ) ;
13951397 let mut js_out = BufWriter :: new ( try_err ! ( File :: create( & js_dst) , & js_dst) ) ;
@@ -1403,10 +1405,15 @@ impl Context {
14031405 Ok ( ( ) )
14041406 } )
14051407 } else if item. name . is_some ( ) {
1406- let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1407-
1408- let dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1409- try_err ! ( render( dst, self , & item, true ) , & joint_dst) ;
1408+ let mut buf = Vec :: new ( ) ;
1409+ render ( & mut buf, self , & item, true ) . unwrap ( ) ;
1410+ // buf will be empty if the item is stripped and there is no redirect for it
1411+ if !buf. is_empty ( ) {
1412+ let joint_dst = self . dst . join ( & item_path ( & item) ) ;
1413+ try_err ! ( fs:: create_dir_all( & self . dst) , & self . dst) ;
1414+ let mut dst = try_err ! ( File :: create( & joint_dst) , & joint_dst) ;
1415+ try_err ! ( dst. write_all( & buf) , & joint_dst) ;
1416+ }
14101417 Ok ( ( ) )
14111418 } else {
14121419 Ok ( ( ) )
0 commit comments