@@ -594,7 +594,8 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
594594 // script_metadata is not needed here, it is only for tests.
595595 let mut rustdoc = cx. compilation . rustdoc_process ( unit, None ) ?;
596596 rustdoc. inherit_jobserver ( & cx. jobserver ) ;
597- rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
597+ let crate_name = unit. target . crate_name ( ) ;
598+ rustdoc. arg ( "--crate-name" ) . arg ( & crate_name) ;
598599 add_path_args ( bcx. ws , unit, & mut rustdoc) ;
599600 add_cap_lints ( bcx, unit, & mut rustdoc) ;
600601
@@ -608,7 +609,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
608609 // it doesn't already exist.
609610 paths:: create_dir_all ( & doc_dir) ?;
610611
611- rustdoc. arg ( "-o" ) . arg ( doc_dir) ;
612+ rustdoc. arg ( "-o" ) . arg ( & doc_dir) ;
612613
613614 for feat in & unit. features {
614615 rustdoc. arg ( "--cfg" ) . arg ( & format ! ( "feature=\" {}\" " , feat) ) ;
@@ -648,6 +649,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
648649 }
649650 }
650651 }
652+ let crate_dir = doc_dir. join ( & crate_name) ;
653+ if crate_dir. exists ( ) {
654+ // Remove output from a previous build. This ensures that stale
655+ // files for removed items are removed.
656+ log:: debug!( "removing pre-existing doc directory {:?}" , crate_dir) ;
657+ paths:: remove_dir_all ( crate_dir) ?;
658+ }
651659 state. running ( & rustdoc) ;
652660
653661 rustdoc
0 commit comments