Skip to content

Commit ae6dbdd

Browse files
committed
Add --remap-path-scope as unstable in rustdoc
1 parent 12f35ad commit ae6dbdd

26 files changed

+270
-2
lines changed

‎compiler/rustc_session/src/config.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ impl OutputFilenames {
13201320
}
13211321
}
13221322

1323-
pub(crate) fn parse_remap_path_scope(
1323+
// pub for rustdoc
1324+
pub fn parse_remap_path_scope(
13241325
early_dcx: &EarlyDiagCtxt,
13251326
matches: &getopts::Matches,
13261327
unstable_opts: &UnstableOptions,

‎src/doc/rustdoc/src/unstable-features.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,12 @@ it permits remapping source path prefixes in all output, including compiler diag
759759
debug information, macro expansions, etc. It takes a value of the form `FROM=TO`
760760
where a path prefix equal to `FROM` is rewritten to the value `TO`.
761761

762+
## `--remap-path-scope`: Scopes to which the source remapping should be done
763+
764+
This flag is the equivalent flag from `rustc` `--remap-path-scope`.
765+
766+
Defines which scopes of paths should be remapped by --remap-path-prefix.
767+
762768
### `documentation` scope
763769

764770
`rustdoc` (and by extension `rustc`) have a special `documentation` remapping scope, it

‎src/librustdoc/config.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_session::config::{
1515
use rustc_session::lint::Level;
1616
use rustc_session::search_paths::SearchPath;
1717
use rustc_session::{EarlyDiagCtxt, getopts};
18-
use rustc_span::FileName;
1918
use rustc_span::edition::Edition;
19+
use rustc_span::{FileName, RemapPathScopeComponents};
2020
use rustc_target::spec::TargetTuple;
2121

2222
use crate::core::new_dcx;
@@ -140,6 +140,8 @@ pub(crate) struct Options {
140140
pub(crate) no_run: bool,
141141
/// What sources are being mapped.
142142
pub(crate) remap_path_prefix: Vec<(PathBuf, PathBuf)>,
143+
/// Which scope(s) to use with `--remap-path-prefix`
144+
pub(crate) remap_path_scope: RemapPathScopeComponents,
143145

144146
/// The path to a rustc-like binary to build tests with. If not set, we
145147
/// default to loading from `$sysroot/bin/rustc`.
@@ -222,6 +224,7 @@ impl fmt::Debug for Options {
222224
.field("no_run", &self.no_run)
223225
.field("test_builder_wrappers", &self.test_builder_wrappers)
224226
.field("remap-file-prefix", &self.remap_path_prefix)
227+
.field("remap-file-scope", &self.remap_path_scope)
225228
.field("no_capture", &self.no_capture)
226229
.field("scrape_examples_options", &self.scrape_examples_options)
227230
.field("unstable_features", &self.unstable_features)
@@ -423,6 +426,8 @@ impl Options {
423426
early_dcx.early_fatal(err);
424427
}
425428
};
429+
let remap_path_scope =
430+
rustc_session::config::parse_remap_path_scope(early_dcx, matches, &unstable_opts);
426431

427432
let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);
428433
let dcx = dcx.handle();
@@ -889,6 +894,7 @@ impl Options {
889894
no_run,
890895
test_builder_wrappers,
891896
remap_path_prefix,
897+
remap_path_scope,
892898
no_capture,
893899
crate_name,
894900
output_format,

‎src/librustdoc/core.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub(crate) fn create_config(
211211
lint_cap,
212212
scrape_examples_options,
213213
remap_path_prefix,
214+
remap_path_scope,
214215
target_modifiers,
215216
..
216217
}: RustdocOptions,
@@ -270,6 +271,7 @@ pub(crate) fn create_config(
270271
crate_name,
271272
test,
272273
remap_path_prefix,
274+
remap_path_scope,
273275
output_types: if let Some(file) = render_options.dep_info() {
274276
OutputTypes::new(&[(OutputType::DepInfo, file.cloned())])
275277
} else {

‎src/librustdoc/doctest.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
171171
target_triple: options.target.clone(),
172172
crate_name: options.crate_name.clone(),
173173
remap_path_prefix: options.remap_path_prefix.clone(),
174+
remap_path_scope: options.remap_path_scope.clone(),
174175
unstable_opts: options.unstable_opts.clone(),
175176
error_format: options.error_format.clone(),
176177
target_modifiers: options.target_modifiers.clone(),

‎src/librustdoc/lib.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,14 @@ fn opts() -> Vec<RustcOptGroup> {
556556
"Remap source names in compiler messages",
557557
"FROM=TO",
558558
),
559+
opt(
560+
Unstable,
561+
Opt,
562+
"",
563+
"remap-path-scope",
564+
"Defines which scopes of paths should be remapped by `--remap-path-prefix`",
565+
"[macro,diagnostics,debuginfo,coverage,object,all]",
566+
),
559567
opt(
560568
Unstable,
561569
FlagMulti,

‎tests/run-make/rustdoc-default-output/output-default.stdout‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ Options:
160160
rustdoc will emit a hard error.
161161
--remap-path-prefix FROM=TO
162162
Remap source names in compiler messages
163+
--remap-path-scope [macro,diagnostics,debuginfo,coverage,object,all]
164+
Defines which scopes of paths should be remapped by
165+
`--remap-path-prefix`
163166
--show-type-layout
164167
Include the memory layout of types in the docs
165168
--no-capture Don't capture stdout and stderr of tests
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This test checks the output of remapping with `--remap-path-prefix` and
2+
// `--remap-path-scope` with a doctest.
3+
4+
//@ failure-status: 101
5+
//@ rustc-env:RUST_BACKTRACE=0
6+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
7+
8+
//@ revisions: with-diag-scope with-macro-scope with-object-scope with-doc-scope
9+
//@ revisions: without-scope
10+
11+
//@ compile-flags:--test --test-args --test-threads=1
12+
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path
13+
14+
//@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics
15+
//@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro
16+
//@[with-object-scope] compile-flags: -Zunstable-options --remap-path-scope=debuginfo
17+
//@[with-doc-scope] compile-flags: -Zunstable-options --remap-path-scope=documentation
18+
19+
/// ```
20+
/// fn invalid(
21+
/// ```
22+
pub struct SomeStruct;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
running 1 test
3+
test $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
8+
error: this file contains an unclosed delimiter
9+
--> $DIR/remap-path-prefix-doctest.rs:20:12
10+
|
11+
LL | fn invalid(
12+
| -^
13+
| |
14+
| unclosed delimiter
15+
16+
error: aborting due to 1 previous error
17+
18+
Couldn't compile the test.
19+
20+
failures:
21+
$DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19)
22+
23+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
24+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
running 1 test
3+
test remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED
4+
5+
failures:
6+
7+
---- remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
8+
error: this file contains an unclosed delimiter
9+
--> remapped_path/remap-path-prefix-doctest.rs:20:12
10+
|
11+
LL | fn invalid(
12+
| -^
13+
| |
14+
| unclosed delimiter
15+
16+
error: aborting due to 1 previous error
17+
18+
Couldn't compile the test.
19+
20+
failures:
21+
remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19)
22+
23+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
24+

0 commit comments

Comments
 (0)