Skip to content

Commit 5db1733

Browse files
committed
rustdoc: forward -Z options to rustc
Currently rustdoc does not forward `-Z` options to rustc when building test executables. This makes impossible to use rustdoc to run test samples when crate under test is instrumented with one of sanitizers `-Zsanitizer=...`, since the final linking step will not include sanitizer runtime library. Forward `-Z` options to rustc to solve the issue. Helps with rust-lang#43031.
1 parent 000d90b commit 5db1733

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

src/librustdoc/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub struct Options {
5353
pub codegen_options_strs: Vec<String>,
5454
/// Debugging (`-Z`) options to pass to the compiler.
5555
pub debugging_options: DebuggingOptions,
56+
/// Debugging (`-Z`) options strings to pass to the compiler.
57+
pub debugging_options_strs: Vec<String>,
5658
/// The target used to compile the crate against.
5759
pub target: TargetTriple,
5860
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
@@ -481,6 +483,7 @@ impl Options {
481483
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
482484
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
483485
let codegen_options_strs = matches.opt_strs("C");
486+
let debugging_options_strs = matches.opt_strs("Z");
484487
let lib_strs = matches.opt_strs("L");
485488
let extern_strs = matches.opt_strs("extern");
486489
let runtool = matches.opt_str("runtool");
@@ -502,6 +505,7 @@ impl Options {
502505
codegen_options,
503506
codegen_options_strs,
504507
debugging_options,
508+
debugging_options_strs,
505509
target,
506510
edition,
507511
maybe_sysroot,

src/librustdoc/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ fn run_test(
279279
for codegen_options_str in &options.codegen_options_strs {
280280
compiler.arg("-C").arg(&codegen_options_str);
281281
}
282+
for debugging_option_str in &options.debugging_options_strs {
283+
compiler.arg("-Z").arg(&debugging_option_str);
284+
}
282285
if no_run {
283286
compiler.arg("--emit=metadata");
284287
}

src/test/rustdoc-ui/failed-doctest-missing-codes.stdout

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ failures:
66

77
---- $DIR/failed-doctest-missing-codes.rs - Foo (line 8) stdout ----
88
error[E0308]: mismatched types
9-
--> $DIR/failed-doctest-missing-codes.rs:9:13
10-
|
11-
3 | let x: () = 5i32;
12-
| ^^^^ expected (), found i32
13-
|
14-
= note: expected type `()`
15-
found type `i32`
9+
--> $DIR/failed-doctest-missing-codes.rs:9:13
10+
|
11+
LL | let x: () = 5i32;
12+
| ^^^^ expected (), found i32
13+
|
14+
= note: expected type `()`
15+
found type `i32`
1616

1717
error: aborting due to previous error
1818

src/test/rustdoc-ui/failed-doctest-output.stdout

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ failures:
77

88
---- $DIR/failed-doctest-output.rs - OtherStruct (line 21) stdout ----
99
error[E0425]: cannot find value `no` in this scope
10-
--> $DIR/failed-doctest-output.rs:22:1
11-
|
12-
3 | no
13-
| ^^ not found in this scope
10+
--> $DIR/failed-doctest-output.rs:22:1
11+
|
12+
LL | no
13+
| ^^ not found in this scope
1414

1515
error: aborting due to previous error
1616

src/test/rustdoc-ui/unparseable-doc-test.stdout

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ failures:
66

77
---- $DIR/unparseable-doc-test.rs - foo (line 6) stdout ----
88
error: unterminated double quote string
9-
--> $DIR/unparseable-doc-test.rs:8:1
10-
|
11-
2 | "unterminated
12-
| ^^^^^^^^^^^^^
9+
--> $DIR/unparseable-doc-test.rs:8:1
10+
|
11+
LL | "unterminated
12+
| ^^^^^^^^^^^^^
1313

1414
error: aborting due to previous error
1515

src/test/rustdoc/sanitizer-option.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// needs-sanitizer-support
2+
// compile-flags: --test -Z sanitizer=address
3+
//
4+
// #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern
5+
// function that is provided by the sanitizer runtime, if flag is not passed
6+
// correctly, then linking will fail.
7+
8+
/// ```
9+
/// extern {
10+
/// fn __sanitizer_print_stack_trace();
11+
/// }
12+
///
13+
/// fn main() {
14+
/// unsafe { __sanitizer_print_stack_trace() };
15+
/// }
16+
/// ```
17+
pub fn z_flag_is_passed_to_rustc() {}

0 commit comments

Comments
 (0)