Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,8 @@ impl OutputFilenames {
}
}

pub(crate) fn parse_remap_path_scope(
// pub for rustdoc
pub fn parse_remap_path_scope(
early_dcx: &EarlyDiagCtxt,
matches: &getopts::Matches,
unstable_opts: &UnstableOptions,
Expand Down
6 changes: 6 additions & 0 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ it permits remapping source path prefixes in all output, including compiler diag
debug information, macro expansions, etc. It takes a value of the form `FROM=TO`
where a path prefix equal to `FROM` is rewritten to the value `TO`.

## `--remap-path-scope`: Scopes to which the source remapping should be done

This flag is the equivalent flag from `rustc` `--remap-path-scope`.

Defines which scopes of paths should be remapped by --remap-path-prefix.

### `documentation` scope

`rustdoc` (and by extension `rustc`) have a special `documentation` remapping scope, it
Expand Down
8 changes: 7 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use rustc_session::config::{
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_session::{EarlyDiagCtxt, getopts};
use rustc_span::FileName;
use rustc_span::edition::Edition;
use rustc_span::{FileName, RemapPathScopeComponents};
use rustc_target::spec::TargetTuple;

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

/// The path to a rustc-like binary to build tests with. If not set, we
/// default to loading from `$sysroot/bin/rustc`.
Expand Down Expand Up @@ -222,6 +224,7 @@ impl fmt::Debug for Options {
.field("no_run", &self.no_run)
.field("test_builder_wrappers", &self.test_builder_wrappers)
.field("remap-file-prefix", &self.remap_path_prefix)
.field("remap-file-scope", &self.remap_path_scope)
.field("no_capture", &self.no_capture)
.field("scrape_examples_options", &self.scrape_examples_options)
.field("unstable_features", &self.unstable_features)
Expand Down Expand Up @@ -423,6 +426,8 @@ impl Options {
early_dcx.early_fatal(err);
}
};
let remap_path_scope =
rustc_session::config::parse_remap_path_scope(early_dcx, matches, &unstable_opts);

let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);
let dcx = dcx.handle();
Expand Down Expand Up @@ -889,6 +894,7 @@ impl Options {
no_run,
test_builder_wrappers,
remap_path_prefix,
remap_path_scope,
no_capture,
crate_name,
output_format,
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub(crate) fn create_config(
lint_cap,
scrape_examples_options,
remap_path_prefix,
remap_path_scope,
target_modifiers,
..
}: RustdocOptions,
Expand Down Expand Up @@ -270,6 +271,7 @@ pub(crate) fn create_config(
crate_name,
test,
remap_path_prefix,
remap_path_scope,
output_types: if let Some(file) = render_options.dep_info() {
OutputTypes::new(&[(OutputType::DepInfo, file.cloned())])
} else {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
target_triple: options.target.clone(),
crate_name: options.crate_name.clone(),
remap_path_prefix: options.remap_path_prefix.clone(),
remap_path_scope: options.remap_path_scope.clone(),
unstable_opts: options.unstable_opts.clone(),
error_format: options.error_format.clone(),
target_modifiers: options.target_modifiers.clone(),
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ fn opts() -> Vec<RustcOptGroup> {
"Remap source names in compiler messages",
"FROM=TO",
),
opt(
Unstable,
Opt,
"",
"remap-path-scope",
"Defines which scopes of paths should be remapped by `--remap-path-prefix`",
"[macro,diagnostics,debuginfo,coverage,object,all]",
),
opt(
Unstable,
FlagMulti,
Expand Down
3 changes: 3 additions & 0 deletions tests/run-make/rustdoc-default-output/output-default.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ Options:
rustdoc will emit a hard error.
--remap-path-prefix FROM=TO
Remap source names in compiler messages
--remap-path-scope [macro,diagnostics,debuginfo,coverage,object,all]
Defines which scopes of paths should be remapped by
`--remap-path-prefix`
--show-type-layout
Include the memory layout of types in the docs
--no-capture Don't capture stdout and stderr of tests
Expand Down
22 changes: 22 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix-doctest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This test checks the output of remapping with `--remap-path-prefix` and
// `--remap-path-scope` with a doctest.

//@ failure-status: 101
//@ rustc-env:RUST_BACKTRACE=0
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"

//@ revisions: with-diag-scope with-macro-scope with-object-scope with-doc-scope
//@ revisions: without-scope

//@ compile-flags:--test --test-args --test-threads=1
//@ compile-flags:-Z unstable-options --remap-path-prefix={{src-base}}=remapped_path

//@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics
//@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro
//@[with-object-scope] compile-flags: -Zunstable-options --remap-path-scope=debuginfo
//@[with-doc-scope] compile-flags: -Zunstable-options --remap-path-scope=documentation

/// ```
/// fn invalid(
/// ```
pub struct SomeStruct;
24 changes: 24 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix-doctest.with-diag-scope.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 1 test
test $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED

failures:

---- $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
error: this file contains an unclosed delimiter
--> $DIR/remap-path-prefix-doctest.rs:20:12
|
LL | fn invalid(
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

24 changes: 24 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix-doctest.with-doc-scope.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 1 test
test remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED

failures:

---- remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
error: this file contains an unclosed delimiter
--> remapped_path/remap-path-prefix-doctest.rs:20:12
|
LL | fn invalid(
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

24 changes: 24 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix-doctest.with-macro-scope.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 1 test
test $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED

failures:

---- $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
error: this file contains an unclosed delimiter
--> $DIR/remap-path-prefix-doctest.rs:20:12
|
LL | fn invalid(
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 1 test
test $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED

failures:

---- $DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
error: this file contains an unclosed delimiter
--> $DIR/remap-path-prefix-doctest.rs:20:12
|
LL | fn invalid(
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/remap-path-prefix-doctest.rs - SomeStruct (line 19)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

24 changes: 24 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix-doctest.without-scope.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 1 test
test remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) ... FAILED

failures:

---- remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19) stdout ----
error: this file contains an unclosed delimiter
--> remapped_path/remap-path-prefix-doctest.rs:20:12
|
LL | fn invalid(
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
remapped_path/remap-path-prefix-doctest.rs - SomeStruct (line 19)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

28 changes: 28 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This test exercises `--remap-path-prefix` and `--remap-path-scope` with macros,
// like file!() and a diagnostic with compile_error!().
//
// See the compiler test suite for a more advanced tests, we just want to
// make sure here that rustdoc passes the right scopes to the underline rustc APIs.

//@ revisions: with-diag-scope with-macro-scope with-debuginfo-scope with-doc-scope
//@ revisions: without-scopes without-remap

//@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped
//@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped
//@[with-debuginfo-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped
//@[with-doc-scope] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped
//@[without-scopes] compile-flags: -Zunstable-options --remap-path-prefix={{src-base}}=remapped

//@[with-diag-scope] compile-flags: -Zunstable-options --remap-path-scope=diagnostics
//@[with-macro-scope] compile-flags: -Zunstable-options --remap-path-scope=macro
//@[with-debuginfo-scope] compile-flags: -Zunstable-options --remap-path-scope=debuginfo
//@[with-doc-scope] compile-flags: -Zunstable-options --remap-path-scope=documentation

compile_error!(concat!("file!() = ", file!()));
//[with-macro-scope]~^ ERROR file!()
//[with-debuginfo-scope]~^^ ERROR file!()
//[with-doc-scope]~^^^ ERROR file!()
//[without-remap]~^^^^ ERROR file!()

//[with-diag-scope]~? ERROR file!()
//[without-scopes]~? ERROR file!()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = $DIR/remap-path-prefix.rs
--> $DIR/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.with-diag-scope.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = $DIR/remap-path-prefix.rs
--> remapped/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.with-doc-scope.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = $DIR/remap-path-prefix.rs
--> $DIR/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.with-macro-scope.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = remapped/remap-path-prefix.rs
--> $DIR/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.without-remap.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = $DIR/remap-path-prefix.rs
--> $DIR/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

8 changes: 8 additions & 0 deletions tests/rustdoc-ui/remap-path-prefix.without-scopes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: file!() = remapped/remap-path-prefix.rs
--> remapped/remap-path-prefix.rs:21:1
|
LL | compile_error!(concat!("file!() = ", file!()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

2 changes: 2 additions & 0 deletions tests/rustdoc-ui/remap-path-scope-invalid.foo.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `documentation`, `debuginfo`, `coverage`, `object`, `all`

10 changes: 10 additions & 0 deletions tests/rustdoc-ui/remap-path-scope-invalid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Error on invalid --remap-path-scope arguments

//@ revisions: foo underscore
//@ compile-flags: -Zunstable-options
//@ [foo]compile-flags: --remap-path-scope=foo
//@ [underscore]compile-flags: --remap-path-scope=macro_object

//~? RAW argument for `--remap-path-scope

fn main() {}
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/remap-path-scope-invalid.underscore.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `documentation`, `debuginfo`, `coverage`, `object`, `all`

7 changes: 7 additions & 0 deletions tests/rustdoc-ui/remap-path-scope-unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Regression test to make sure `--remap-path-scope` is unstable in rustdoc

//@ compile-flags:--remap-path-scope macro

//~? RAW the `-Z unstable-options` flag must also be passed to enable the flag `remap-path-scope`

fn main() {}
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/remap-path-scope-unstable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: the `-Z unstable-options` flag must also be passed to enable the flag `remap-path-scope`

Loading