@@ -97,6 +97,7 @@ use crate::util::{add_path_args, internal};
97
97
use cargo_util:: { paths, ProcessBuilder , ProcessError } ;
98
98
use cargo_util_schemas:: manifest:: TomlDebugInfo ;
99
99
use cargo_util_schemas:: manifest:: TomlTrimPaths ;
100
+ use cargo_util_schemas:: manifest:: TomlTrimPathsValue ;
100
101
use rustfix:: diagnostics:: Applicability ;
101
102
102
103
const RUSTDOC_CRATE_VERSION_FLAG : & str = "--crate-version" ;
@@ -737,6 +738,10 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu
737
738
add_error_format_and_color ( build_runner, & mut rustdoc) ;
738
739
add_allow_features ( build_runner, & mut rustdoc) ;
739
740
741
+ if let Some ( trim_paths) = unit. profile . trim_paths . as_ref ( ) {
742
+ trim_paths_args_rustdoc ( & mut rustdoc, build_runner, unit, trim_paths) ?;
743
+ }
744
+
740
745
rustdoc. args ( unit. pkg . manifest ( ) . lint_rustflags ( ) ) ;
741
746
if let Some ( args) = build_runner. bcx . extra_args_for ( unit) {
742
747
rustdoc. args ( args) ;
@@ -1223,6 +1228,32 @@ fn features_args(unit: &Unit) -> Vec<OsString> {
1223
1228
args
1224
1229
}
1225
1230
1231
+ /// Like [`trim_paths_args`] but for rustdoc invocations.
1232
+ fn trim_paths_args_rustdoc (
1233
+ cmd : & mut ProcessBuilder ,
1234
+ build_runner : & BuildRunner < ' _ , ' _ > ,
1235
+ unit : & Unit ,
1236
+ trim_paths : & TomlTrimPaths ,
1237
+ ) -> CargoResult < ( ) > {
1238
+ match trim_paths {
1239
+ // rustdoc supports diagnostics trimming only.
1240
+ TomlTrimPaths :: Values ( values) if !values. contains ( & TomlTrimPathsValue :: Diagnostics ) => {
1241
+ return Ok ( ( ) )
1242
+ }
1243
+ _ => { }
1244
+ }
1245
+
1246
+ // feature gate was checked during manifest/config parsing.
1247
+ cmd. arg ( "-Zunstable-options" ) ;
1248
+
1249
+ // Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
1250
+ // We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
1251
+ cmd. arg ( package_remap ( build_runner, unit) ) ;
1252
+ cmd. arg ( sysroot_remap ( build_runner, unit) ) ;
1253
+
1254
+ Ok ( ( ) )
1255
+ }
1256
+
1226
1257
/// Generates the `--remap-path-scope` and `--remap-path-prefix` for [RFC 3127].
1227
1258
/// See also unstable feature [`-Ztrim-paths`].
1228
1259
///
0 commit comments