Skip to content

Commit

Permalink
Rollup merge of rust-lang#65314 - tmiasko:rustdoc-z, r=ollie27
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Centril authored Oct 20, 2019
2 parents 7979016 + 5db1733 commit 194d193
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct Options {
pub codegen_options_strs: Vec<String>,
/// Debugging (`-Z`) options to pass to the compiler.
pub debugging_options: DebuggingOptions,
/// Debugging (`-Z`) options strings to pass to the compiler.
pub debugging_options_strs: Vec<String>,
/// The target used to compile the crate against.
pub target: TargetTriple,
/// Edition used when reading the crate. Defaults to "2015". Also used by default when
Expand Down Expand Up @@ -478,6 +480,7 @@ impl Options {
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
let codegen_options_strs = matches.opt_strs("C");
let debugging_options_strs = matches.opt_strs("Z");
let lib_strs = matches.opt_strs("L");
let extern_strs = matches.opt_strs("extern");
let runtool = matches.opt_str("runtool");
Expand All @@ -499,6 +502,7 @@ impl Options {
codegen_options,
codegen_options_strs,
debugging_options,
debugging_options_strs,
target,
edition,
maybe_sysroot,
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ fn run_test(
for codegen_options_str in &options.codegen_options_strs {
compiler.arg("-C").arg(&codegen_options_str);
}
for debugging_option_str in &options.debugging_options_strs {
compiler.arg("-Z").arg(&debugging_option_str);
}
if no_run {
compiler.arg("--emit=metadata");
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/rustdoc-ui/failed-doctest-missing-codes.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ failures:

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

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/failed-doctest-output.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ failures:

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

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/unparseable-doc-test.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ failures:

---- $DIR/unparseable-doc-test.rs - foo (line 6) stdout ----
error: unterminated double quote string
--> $DIR/unparseable-doc-test.rs:8:1
|
2 | "unterminated
| ^^^^^^^^^^^^^
--> $DIR/unparseable-doc-test.rs:8:1
|
LL | "unterminated
| ^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/sanitizer-option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// needs-sanitizer-support
// compile-flags: --test -Z sanitizer=address
//
// #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern
// function that is provided by the sanitizer runtime, if flag is not passed
// correctly, then linking will fail.

/// ```
/// extern {
/// fn __sanitizer_print_stack_trace();
/// }
///
/// fn main() {
/// unsafe { __sanitizer_print_stack_trace() };
/// }
/// ```
pub fn z_flag_is_passed_to_rustc() {}

0 comments on commit 194d193

Please sign in to comment.