@@ -594,7 +594,8 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
594
594
// script_metadata is not needed here, it is only for tests.
595
595
let mut rustdoc = cx. compilation . rustdoc_process ( unit, None ) ?;
596
596
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) ;
598
599
add_path_args ( bcx. ws , unit, & mut rustdoc) ;
599
600
add_cap_lints ( bcx, unit, & mut rustdoc) ;
600
601
@@ -608,7 +609,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
608
609
// it doesn't already exist.
609
610
paths:: create_dir_all ( & doc_dir) ?;
610
611
611
- rustdoc. arg ( "-o" ) . arg ( doc_dir) ;
612
+ rustdoc. arg ( "-o" ) . arg ( & doc_dir) ;
612
613
613
614
for feat in & unit. features {
614
615
rustdoc. arg ( "--cfg" ) . arg ( & format ! ( "feature=\" {}\" " , feat) ) ;
@@ -648,6 +649,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
648
649
}
649
650
}
650
651
}
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
+ }
651
659
state. running ( & rustdoc) ;
652
660
653
661
rustdoc
0 commit comments